Hey guys, I am facing following problem:

我的项目是 Build 在Angular4上的打字稿,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无法正常工作 .

我已经检查了@types和tsconfig的文档以及github上的相关问题,但我认为这里的行为不正确 . 文件声明,

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

那为什么要尝试包含所有的.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的详细信息:

node v7.4.0 npm v4.1.2 typescript@2.3.4 protractor@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

What I have already tried:

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

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

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

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

如何解决这个问题,只加载适当的.ts文件?在此先感谢您的帮助!

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

额外资源: