Angular 使用require()

2021-03-18  本文已影响0人  高阳刘

require是node.js中常用方法,用于引入模块、 JSON、或本地文件。
Angular使用会报错

Cannot find name 'require'. Do you need to install type definitions for node? Try npm i @types/node and then add node to the types field in your tsconfig.

解决办法
在tsconfig.app.json文件中
设置

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "./out-tsc/app",
    "types": [
      "node"
    ]
  },
  "files": [
    "src/main.ts",
    "src/polyfills.ts"
  ],
  "include": [
    "src/**/*.d.ts"
  ]

https://www.jianshu.com/p/a01e27bd8d48

上一篇 下一篇

猜你喜欢

热点阅读