typescript error: would overwrite input file

a 夏天 提交于 2019-12-12 19:07:50

问题


I have updated latest Ionic version and removed src/declarations.d.ts file.Now my app shows below error when I try to run the app ionic serve.

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:  (() => {

I have found the solution for it and now above error is not there.But now it shows below error.

typescript error Cannot write file '/sophy/node_modules/nprogress/nprogress.js' because it would overwrite input file.

Do you know why?

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
  }
}

I think this is the issue here.So how can I solve it? When I remove the declarations.d.ts then above errors are coming.If I add it then no issues (I have to remove the "allowJs": true too).Any solution, please.

src\assets\load.ts

  import * as NProgress from '../../../node_modules/nprogress/nprogress.js'
    (() => {
      NProgress.start();
    })()

回答1:


You can try using the type declarations for the js library.

npm install --save-dev @types/nProgress

The declaration file can be seen here. It will be added to node_modules/@types directory. Do

 import Nprogress from 'nprogress'


来源:https://stackoverflow.com/questions/44457138/typescript-error-would-overwrite-input-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!