我正在尝试编译TypeScript代码(.tsx - > .js)以打包Webpack,这样我就可以做一些前端工作并在浏览器中运行代码。 (我实际上有更多要求,比如需要与Node.js服务器共享一些前端(浏览器)TypeScript代码并在Electron中运行所有这些东西,但这些是次要的。)
我刚刚听完了这个教程:
当我在最后键入webpack
时,我遇到了1000多个错误(截断):
$ webpack
[at-loader] Using typescript@2.1.4 from typescript and "tsconfig.json" from /Users/jupdike/Documents/dev/tsrw/proj/tsconfig.json.
[at-loader] Checking started in a separate process...
[at-loader] Checking finished with 1065 errors
Hash: 7aedcf2d5d64f9ada335
Version: webpack 1.14.0
Time: 3264ms
Asset Size Chunks Chunk Names
bundle.js 2.94 kB 0 [emitted] main
bundle.js.map 3.04 kB 0 [emitted] main
+ 4 hidden modules
ERROR in [at-loader] node_modules/awesome-typescript-loader/dist/test/utils.d.ts:3:24
Cannot find module 'chai'.
ERROR in [at-loader] node_modules/awesome-typescript-loader/dist/test/utils.d.ts:25:50
Parameter 'err' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/dist/test/utils.d.ts:25:55
Parameter 'stats' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/lib/runtime.d.ts:20:13
Subsequent variable declarations must have the same type. Variable 'require' must be of type 'NodeRequire', but here has type 'WebpackRequire'.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/cache.ts:43:23
Argument of type 'Buffer' is not assignable to parameter of type 'string'.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/cache.ts:66:35
Parameter 'identifier' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/cache.ts:66:47
Parameter 'options' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/checker/checker.ts:1:20
Could not find a declaration file for module 'lodash'. '/Users/jupdike/Documents/dev/tsrw/proj/node_modules/lodash/lodash.js' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/checker/runtime.ts:2:47
Parameter 'err' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/checker/runtime.ts:17:20
Parameter 'msg' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/checker/runtime.ts:30:28
Parameter 'cb' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/checker/runtime.ts:41:25
Cannot find module 'colors'.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/checker/runtime.ts:195:13
Parameter 'message' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/checker/runtime.ts:199:20
Rest parameter 'args' implicitly has an 'any[]' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/checker/runtime.ts:203:18
Rest parameter 'args' implicitly has an 'any[]' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/checker/runtime.ts:207:23
Rest parameter 'args' implicitly has an 'any[]' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/checker/runtime.ts:219:24
Rest parameter 'args' implicitly has an 'any[]' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/checker/send.ts:15:9
Variable 'msgQueue' implicitly has type 'any[]' in some locations where its type cannot be determined.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/checker/send.ts:20:13
Variable 'msgQueue' implicitly has an 'any[]' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/checker/send.ts:24:45
Parameter 'error' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/checker/send.ts:32:17
Variable 'msgQueue' implicitly has an 'any[]' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/checker/send.ts:33:38
Variable 'msgQueue' implicitly has an 'any[]' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/helpers.ts:19:21
Parameter 'fileName' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/helpers.ts:19:31
Parameter 'outputFileName' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/helpers.ts:19:47
Parameter 'sourceFileName' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/helpers.ts:25:26
Parameter 'fileName' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/helpers.ts:25:36
Parameter 'outputFileName' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/helpers.ts:25:52
Parameter 'sourceFileName' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/helpers.ts:31:28
Parameter 'fileName' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/helpers.ts:31:38
Parameter 'outputFileName' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/helpers.ts:31:54
Parameter 'sourceFileName' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/helpers.ts:64:36
Parameter 'errors' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/helpers.ts:66:24
Parameter 'error' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/helpers.ts:72:29
Parameter 'diagnostic' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/helpers.ts:105:32
Parameter 'lineChar' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/helpers.ts:109:25
Parameter 'moduleId' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/index.ts:3:20
Could not find a declaration file for module 'lodash'. '/Users/jupdike/Documents/dev/tsrw/proj/node_modules/lodash/lodash.js' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/index.ts:14:17
Parameter 'text' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/instance.ts:3:20
Could not find a declaration file for module 'lodash'. '/Users/jupdike/Documents/dev/tsrw/proj/node_modules/lodash/lodash.js' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/instance.ts:49:10
'getRootCompiler' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/instance.ts:49:26
Parameter 'compiler' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/instance.ts:57:27
Parameter 'compiler' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/instance.ts:66:30
Parameter 'compiler' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/instance.ts:73:26
Parameter 'compiler' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/instance.ts:73:36
Parameter 'instanceName' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/instance.ts:141:10
'findTsImplPackage' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/instance.ts:246:21
Parameter 'fileName' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/instance.ts:299:24
Parameter 'compiler' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/instance.ts:300:44
Parameter 'watching' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/instance.ts:300:54
Parameter 'callback' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/instance.ts:339:28
Parameter 'compiler' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/instance.ts:339:38
Parameter 'instanceName' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/instance.ts:340:48
Parameter 'compilation' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/instance.ts:340:61
Parameter 'callback' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/instance.ts:352:26
Parameter 'msg' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/instance.ts:367:21
Binding element 'files' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/instance.ts:374:23
Parameter 'diags' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/instance.ts:375:35
Parameter 'diag' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/paths-plugin.ts:4:20
Could not find a declaration file for module 'lodash'. '/Users/jupdike/Documents/dev/tsrw/proj/node_modules/lodash/lodash.js' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/paths-plugin.ts:36:5
'plugin', which lacks return-type annotation, implicitly has an 'any' return type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/paths-plugin.ts:37:5
'doResolve', which lacks return-type annotation, implicitly has an 'any' return type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/paths-plugin.ts:37:59
Parameter 'Callback' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/paths-plugin.ts:48:23
Parameter 'str' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/paths-plugin.ts:117:17
Parameter 'request' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/paths-plugin.ts:117:26
Parameter 'callback' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/babel.ts:6:1
Cannot find name 'describe'.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/babel.ts:8:5
Cannot find name 'it'.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/babel.ts:32:5
Cannot find name 'it'.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/declaration.ts:6:1
Cannot find name 'describe'.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/declaration.ts:8:5
Cannot find name 'xit'.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/fixtures/babel/babel.ts:1:7
Duplicate identifier 'HiThere'.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/fixtures/basic/basic.ts:1:7
Duplicate identifier 'HiThere'.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/fixtures/errors/with-type-errors.ts:3:26
Argument of type 'number' is not assignable to parameter of type 'boolean'.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/fixtures/salsa/index.ts:1:21
Module './lib' was resolved to '/Users/jupdike/Documents/dev/tsrw/proj/node_modules/awesome-typescript-loader/src/test/fixtures/salsa/lib.js', but '--allowJs' is not set.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/fixtures/typeRoots/index.ts:2:1
Cannot find name 'describe'.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/index.ts:6:1
Cannot find name 'describe'.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/index.ts:8:5
Cannot find name 'it'.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/index.ts:23:5
Cannot find name 'it'.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/index.ts:32:5
Cannot find name 'it'.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/index.ts:43:5
Cannot find name 'it'.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/index.ts:54:45
Object literal's property 'configFileContent' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/react.ts:6:1
Cannot find name 'describe'.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/react.ts:7:5
Cannot find name 'it'.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/salsa.ts:6:1
Cannot find name 'describe'.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/salsa.ts:7:5
Cannot find name 'it'.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/salsa.ts:13:45
Object literal's property 'configFileContent' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/salsa.ts:19:5
Cannot find name 'xit'.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/salsa.ts:25:45
Object literal's property 'configFileContent' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/typeRoots.ts:6:1
Cannot find name 'describe'.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/typeRoots.ts:7:5
Cannot find name 'it'.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/utils.ts:5:20
Could not find a declaration file for module 'lodash'. '/Users/jupdike/Documents/dev/tsrw/proj/node_modules/lodash/lodash.js' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/utils.ts:12:24
Cannot find module 'chai'.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/utils.ts:38:30
Parameter 'conf' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/utils.ts:70:9
Object literal's property 'plugins' implicitly has an 'any[]' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/utils.ts:108:36
Parameter 'buf' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/utils.ts:118:15
Parameter 'buf' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/utils.ts:119:15
Parameter 'source' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/utils.ts:127:76
Parameter 'buf' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/utils.ts:135:33
Parameter 'config' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/utils.ts:140:25
Parameter 'config' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/utils.ts:143:23
Parameter 'err' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/utils.ts:143:28
Parameter 'stats' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/utils.ts:153:23
Parameter 'config' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/utils.ts:153:37
Parameter 'err' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/utils.ts:153:42
Parameter 'stats' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/utils.ts:156:46
Parameter 'err' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/utils.ts:156:51
Parameter 'stats' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/utils.ts:171:10
Parameter 'err' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/utils.ts:171:15
Parameter 'stats' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/watch-type-errors.ts:5:1
Cannot find name 'describe'.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/watch-type-errors.ts:23:5
Cannot find name 'it'.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/without-sourcemap.ts:6:1
Cannot find name 'describe'.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/test/without-sourcemap.ts:7:5
Cannot find name 'it'.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/watch-mode.ts:4:11
Parameter 'compiler' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/watch-mode.ts:5:41
Parameter 'params' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/watch-mode.ts:5:49
Parameter 'callback' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/watch-mode.ts:10:47
Parameter 'params' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/awesome-typescript-loader/src/watch-mode.ts:10:55
Parameter 'callback' implicitly has an 'any' type.
ERROR in [at-loader] node_modules/typescript/Gulpfile.ts:1:1
File '/Users/jupdike/Documents/dev/tsrw/proj/node_modules/typescript/scripts/types/ambient.d.ts' not found.
ERROR in [at-loader] node_modules/typescript/Gulpfile.ts:5:31
Cannot find module 'gulp'.
ERROR in [at-loader] node_modules/typescript/Gulpfile.ts:6:28
Cannot find module 'gulp-help'.
ERROR in [at-loader] node_modules/typescript/Gulpfile.ts:7:30
Cannot find module 'run-sequence'.
ERROR in [at-loader] node_modules/typescript/Gulpfile.ts:8:25
Cannot find module 'gulp-concat'.
ERROR in [at-loader] node_modules/typescript/Gulpfile.ts:9:24
Cannot find module 'gulp-clone'.
ERROR in [at-loader] node_modules/typescript/Gulpfile.ts:10:24
Cannot find module 'gulp-newer'.
ERROR in [at-loader] node_modules/typescript/Gulpfile.ts:11:22
Cannot find module 'gulp-typescript'.
ERROR in [at-loader] node_modules/typescript/Gulpfile.ts:12:16
Invalid module name in augmentation, module 'gulp-typescript' cannot be found.
ERROR in [at-loader] node_modules/typescript/Gulpfile.ts:21:25
Cannot find module 'gulp-insert'.
ERROR in [at-loader] node_modules/typescript/Gulpfile.ts:22:29
Cannot find module 'gulp-sourcemaps'.
ERROR in [at-loader] node_modules/typescript/Gulpfile.ts:23:20
Cannot find module 'q'.
ERROR in [at-loader] node_modules/typescript/Gulpfile.ts:26:10
Duplicate identifier 'Promise'.
ERROR in [at-loader] node_modules/typescript/Gulpfile.ts:28:22
Cannot find module 'del'.
ERROR in [at-loader] node_modules/typescript/Gulpfile.ts:29:25
Cannot find module 'mkdirp'.
ERROR in [at-loader] node_modules/typescript/Gulpfile.ts:30:27
Could not find a declaration file for module 'minimist'. '/Users/jupdike/node_modules/minimist/index.js' implicitly has an 'any' type.
是否有任何其他教程或骨架/引导程序下载可以帮助我按照我描述的方式设置测试项目?或者有没有办法调整本教程,以便它按预期工作,而不是比尝试只遵循一个Webpack教程更糟糕?似乎awesome-typescript-loader插件不是。
(顺便说一句,我只是疯了,或者像#34;狂野西部(或#34;让1000朵花绽放",取决于你的观点)的JS / Node生态系统。所有这些工具应该让JS开发更加方便和强大,具有非常高的前期复杂性成本,具有无限的灵活性,但它们需要大量的牦牛皮。我是否独自一人?)
答案 0 :(得分:2)
根据我之前的评论,您可以告诉编译器排除可能已经过类型检查的库。从该教程中,他们为您提供的tsconfig.json
文件看起来像这样
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "es5",
"jsx": "react"
},
"include": [
"./**/*"
]
}
尝试将其更改为此
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "es5",
"jsx": "react"
},
"include": [
"./**/*"
],
"exclude": [
"node_modules"
]
}