打字稿错误:将覆盖输入文件 [英] typescript error: would overwrite input file

查看:20
本文介绍了打字稿错误:将覆盖输入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已更新 最新 Ionic 版本 并删除了 src/declarations.d.ts 文件.现在,当我尝试运行应用程序 ionic serve 时,我的应用程序显示以下错误.

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.

打字稿:/sophy/src/assets/dev-load/load.ts,行:1模块../../../node_modules/nprogress/nprogress.js"被解析为/sophy/node_modules/nprogress/nprogress.js",但是'--allowJs' 未设置.

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.

打字稿错误无法写入文件'/sophy/node_modules/nprogress/nprogress.js',因为它会覆盖输入文件.

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 ).请有任何解决方案.

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.

srcassetsload.ts

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

推荐答案

你可以尝试使用js库的类型声明.

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

npm install --save-dev @types/nProgress

声明文件可见这里.它将被添加到 node_modules/@types 目录中.做

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

 import Nprogress from 'nprogress'

这篇关于打字稿错误:将覆盖输入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆