0

嘿伙计们,我面临以下问题:

我的项目建立在 Angular4 上,带有 typescript,使用量角器和 karma 进行 e2e 测试。但是几天以来,我不断收到以下错误:

File 'D:/myproject/node_modules/protractor/package.json' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'. (
6054)
File 'D:/myproject/node_modules/q/package.json' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'. (6054)
File 'D:/myproject/node_modules/selenium-webdriver/package.json' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.
d.ts'. (6054)
File 'D:/myproject/node_modules/source-map/package.json' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'. (
6054)
File 'D:/myproject/node_modules/tapable/package.json' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'. (605
4)
File 'D:/myproject/node_modules/tslib/package.json' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'. (6054)

File 'D:/myproject/node_modules/uglify-js/package.json' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'. (6
054)
File 'D:/myproject/node_modules/webdriver-js-extender/node_modules/selenium-webdriver/package.json' has unsupported extension. The only support
ed extensions are '.ts', '.tsx', '.d.ts'. (6054)
File 'D:/myproject/node_modules/webdriver-js-extender/package.json' has unsupported extension. The only supported extensions are '.ts', '.tsx',
 '.d.ts'. (6054)
    at getOutput (D:\myproject\node_modules\ts-node\src\index.ts:300:15)
    at D:\myproject\node_modules\ts-node\src\index.ts:330:16
    at Object.compile (D:\myproject\node_modules\ts-node\src\index.ts:489:17)
    at Module.m._compile (D:\myproject\node_modules\ts-node\src\index.ts:382:43)
    at Module._extensions..js (module.js:580:10)
    at Object.require.extensions.(anonymous function) [as .ts] (D:\myproject\node_modules\ts-node\src\index.ts:385:12)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
[23:41:57] E/launcher - Process exited with error code 100

据我了解错误消息,typscript 加载程序尝试转换非 ts 文件。可以肯定的是,在发布我的问题之前,我已经搜索了整个互联网,而且我的tsconfig.json中的 @types 似乎无法正常工作。

我已经在 github 上检查了 @types 和 tsconfig 以及相关问题的文档,但我认为这里的行为不正确。文档指出,

仅包含具有受支持扩展名的文件(例如,如果 allowJs 设置为 true,则默认为 .js 和 .jsx 的 .ts、.tsx 和 .d.ts)。

那它为什么要包含所有的 .json 文件呢?


tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "noEmit": true,
    "noEmitHelpers": true,
    "importHelpers": true,
    "strictNullChecks": false,
    "lib": [
      "dom",
      "es6"
    ],
    "typeRoots": [
      "node_modules/@types"
    ],
    "types": [
      "hammerjs",
      "jasmine",
      "node",
      "source-map",
      "uglify-js",
      "webpack"
    ]
  },
  "exclude": [
    "node_modules",
    "dist"
  ],
  "awesomeTypescriptLoaderOptions": {
    "forkChecker": true,
    "useWebpackText": true
  },
  "compileOnSave": false,
  "buildOnSave": false,
  "atom": {
    "rewriteTsconfig": false
  }
}

myproject的详细信息:

节点 v7.4.0

npm v4.1.2

打字稿@2.3.4

量角器@5.1.2

├── src/
│   ├── custom-typings.d.ts
├── node_modules/
│   ├── @types
│   |   ├── hammerjs
│   |   |   ├── index.d.ts
│   |   |   ├── package.json
│   |   |   ├── README.md
│   |   |   ├── types-metadata.json
│   |   ├── jasmine
│   |   |   ├── index.d.ts
│   |   |   ├── ...
│   |   ├── node
│   |   |   ├── index.d.ts
│   |   |   ├── ...
│   |   ├── source-map
│   |   |   ├── index.d.ts
│   |   |   ├── ...
│   |   ├── uglify-js
│   |   |   ├── index.d.ts
│   |   |   ├── ...
│   |   ├── webpack
│   |   |   ├── index.d.ts
│   |   |   ├── ...
│   |   ├── ...
│   └── (@agm, @angular, ...)
└── package.json

我已经尝试过的:

  • 删除排除块,因为它包含与默认值相同:

当未指定时,“exclude”属性默认排除 node_modules、bower_components、jspm_packages 和目录。

  • 设置选项“allowJs:true”,导致文件加载器丢失(不是合适的解决方案)

  • 删除 typeRoots 以使用默认设置,导致相同的错误

我该如何解决这个问题,只加载适当的 .ts 文件?提前感谢您的帮助!

  • 添加"include": [ "src/**/*" ]"include": [ "src/**/*.ts" ]- 导致相同的错误

额外资源:

4

0 回答 0