我已更新latest Ionic version并删除了 src/declarations.d.ts 文件。现在,当我尝试运行应用程序 ionicserve 时,我的应用程序显示以下错误。
typescript: /sophy/src/assets/dev-load/load.ts, line: 1 Module '../../../node_modules/nprogress/nprogress.js' was resolved to '/sophy/node_modules/nprogress/nprogress.js', but '--allowJs' is not set.
L1: import * as NProgress from '../../../node_modules/nprogress/nprogress.js' L2: (() => {
我have found the solution对于它,现在上面的错误不存在。但现在它显示下面的错误。
typescript error Cannot write file '/sophy/node_modules/nprogress/nprogress.js' because it would overwrite input file.
你知道为什么吗?
tsconfig.json
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"dom",
"es2015"
],
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"target": "es5",
"allowJs": true
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
],
"compileOnSave": false,
"atom": {
"rewriteTsconfig": false
}
}
我认为这就是问题所在。那么我该如何解决呢?当我删除 declarations.d.ts
时,就会出现上述错误。如果我添加它,则没有问题(我也必须删除 "allowJs": true
)。任何解决方案,请。
src\assets\load.ts
import * as NProgress from '../../../node_modules/nprogress/nprogress.js'
(() => {
NProgress.start();
})()
最佳答案
您可以尝试使用 js 库的类型声明。
npm install --save-dev @types/nProgress
声明文件可见here 。
它将被添加到 node_modules/@types
目录中。
做
import Nprogress from 'nprogress'
关于 typescript 错误: would overwrite input file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44457138/