【发布时间】:2017-08-14 04:59:39
【问题描述】:
我有一个项目文件夹,其根级别为node_modules,另一个位于名为functions 的子文件夹中。像这样,
├── functions
│ ├── index.js
│ ├── index.js.map
│ ├── index.ts
│ ├── package.json
│ ├── node_modules
│ └── tsconfig.json
├── package.json
└── node_modules
我想在functions 文件夹中编译打字稿文件,但它一直在查看根 node_modules 并给我错误,
tsc --project functions
functions/node_modules/@types/node/index.d.ts(60,13): error TS2451: Cannot redeclare block-scoped variable 'global'.
functions/node_modules/@types/node/index.d.ts(84,13): error TS2300: Duplicate identifier 'require'.
node_modules/@types/react-native/index.d.ts(8365,11): error TS2451: Cannot redeclare block-scoped variable 'global'.
node_modules/@types/react-native/index.d.ts(8366,14): error TS2300: Duplicate identifier 'require'.
如何让 typescript 忘记上层 node_modules 或以其他方式解决此问题?
tsconfig.json:
{
"compilerOptions": {
"target": "es2015",
"module": "CommonJS",
"outDir": ".",
"rootDir": ".",
"allowSyntheticDefaultImports": true,
"noImplicitAny": true,
"experimentalDecorators": true,
"preserveConstEnums": true,
"allowJs": true,
"sourceMap": true
},
"filesGlob": [
"./**/*.ts"
],
"exclude": [
"node_modules"
],
"compileOnSave": false
}
【问题讨论】:
-
也许:
cd functions && tsc。tsconfig.json的内容是什么? -
cd 没有任何区别。添加了 tsconfig
标签: typescript npm