-
Notifications
You must be signed in to change notification settings - Fork 574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build报错 #183
Comments
node版本,typscript版本,@types/node 版本是多少 |
node:10.11.0 typescript:3.2.0 @types/node:10.5.5 |
没有动 tsconfig.json, 我这边用的是mac系统,是否与系统有关呢 |
我也是mac。。 |
是不是tslint.json的原因,以前的项目更新到新版midway,npm run build 也编译不通过,用midway-init 新建项目就可以编译 ../node_modules/@types/jasmine/index.d.ts:9:1 - error TS6200: Definitions of the following identifiers conflict with those in another file: describe, fdescribe, xdescribe, it, fit, xit, beforeEach, afterEach, beforeAll, afterAll, expect, clock, CustomEqualityTester, CustomMatcherFactory, DEFAULT_TIMEOUT_INTERVAL
9 declare function describe(description: string, specDefinitions: () => void): void;
~~~~~~~
node_modules/@types/jest/index.d.ts:26:1
26 declare var beforeAll: jest.Lifecycle;
~~~~~~~
Conflicts are in this file.
../node_modules/@types/jasmine/index.d.ts:74:9 - error TS2375: Duplicate number index signature.
74 [n: number]: T;
~~~~~~~~~~~~~~~
../node_modules/@types/jasmine/index.d.ts:129:9 - error TS2374: Duplicate string index signature.
129 [index: string]: CustomMatcherFactory;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../node_modules/@types/jasmine/index.d.ts:134:9 - error TS2687: All declarations of 'message' must have identical modifiers.
134 message?: string;
~~~~~~~
../node_modules/@types/jasmine/index.d.ts:134:9 - error TS2717: Subsequent property declarations must have the same type. Property 'message' must be of type 'string | (() => string)', but here has type 'string'.
134 message?: string;
~~~~~~~
node_modules/@types/jest/index.d.ts:26:1 - error TS6200: Definitions of the following identifiers conflict with those in another file: describe, fdescribe, xdescribe, it, fit, xit, beforeEach, afterEach, beforeAll, afterAll, expect, clock, CustomEqualityTester, CustomMatcherFactory, DEFAULT_TIMEOUT_INTERVAL
26 declare var beforeAll: jest.Lifecycle;
~~~~~~~
../node_modules/@types/jasmine/index.d.ts:9:1
9 declare function describe(description: string, specDefinitions: () => void): void;
~~~~~~~
Conflicts are in this file.
node_modules/@types/jest/index.d.ts:1218:9 - error TS2687: All declarations of 'message' must have identical modifiers.
1218 message: string | (() => string);
~~~~~~~
node_modules/@types/mocha/index.d.ts:2680:13 - error TS2403: Subsequent variable declarations must have the same type. Variable 'beforeEach' must be of type 'Lifecycle', but here has type 'HookFunction'.
2680 declare var beforeEach: Mocha.HookFunction;
~~~~~~~~~~
node_modules/@types/mocha/index.d.ts:2698:13 - error TS2403: Subsequent variable declarations must have the same type. Variable 'afterEach' must be of type 'Lifecycle', but here has type 'HookFunction'.
2698 declare var afterEach: Mocha.HookFunction;
~~~~~~~~~
node_modules/@types/mocha/index.d.ts:2714:13 - error TS2403: Subsequent variable declarations must have the same type. Variable 'describe' must be of type 'Describe', but here has type 'SuiteFunction'.
2714 declare var describe: Mocha.SuiteFunction;
~~~~~~~~
node_modules/@types/mocha/index.d.ts:2735:13 - error TS2403: Subsequent variable declarations must have the same type. Variable 'xdescribe' must be of type 'Describe', but here has type 'PendingSuiteFunction'.
2735 declare var xdescribe: Mocha.PendingSuiteFunction;
~~~~~~~~~
node_modules/@types/mocha/index.d.ts:2749:13 - error TS2403: Subsequent variable declarations must have the same type. Variable 'it' must be of type 'It', but here has type 'TestFunction'.
2749 declare var it: Mocha.TestFunction;
~~
node_modules/@types/mocha/index.d.ts:2763:13 - error TS2403: Subsequent variable declarations must have the same type. Variable 'test' must be of type 'It', but here has type 'TestFunction'.
2763 declare var test: Mocha.TestFunction;
~~~~
node_modules/@types/mocha/index.d.ts:2770:13 - error TS2403: Subsequent variable declarations must have the same type. Variable 'xit' must be of type 'It', but here has type 'PendingTestFunction'.
2770 declare var xit: Mocha.PendingTestFunction;
~~~
Found 14 errors. |
他这个也是新建的项目吧。 |
嗯嗯,新建项目没有问题,我的项目报错是因为@types/mocha和@types/jest同时安装冲突😭 |
@czy88840616 大佬,这个问题怎么解决呢~ |
我本地一直没重现..你那有能重现的demo么…… |
@czy88840616 劳烦大佬看看了 第一个 这个是直接 init 创建,然后 yarn 安装依赖,直接 build 的时候会报错,但是在升级了 package.json 里面的依赖后,是可以正常 build 的 第二个 这个是因为在 tsconfig.json 里面定义了 paths 路径别名导致的,已经使用了
更新:第二个的原因已找到,详情看 这里,原因是因为 |
第一个已重现,这个有出现过,@Lellansin 有方案修复。加一段 baseUrl 和 Paths {
"compileOnSave": true,
"compilerOptions": {
"baseUrl" : "./",
"paths": {
"*" : ["./node_modules/@types/*", "*"]
},
"target": "ES2017",
"module": "commonjs",
"moduleResolution": "node",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"inlineSourceMap":true,
"noImplicitThis": true,
"noUnusedLocals": true,
"stripInternal": true,
"pretty": true,
"declaration": true,
"outDir": "dist",
"lib": ["es2017", "dom"]
},
"exclude": [
"dist",
"node_modules",
"test"
]
} |
看起来是 tsc 编译的时候没有 ignore 了 exclude 的 node_modules。具体 tsc 的表现可以参见文档 Why is a file in the exclude list still picked up by the compiler? |
@czy88840616 大佬,另外有一个问题,在 build 之后,paths 定义的路径别名没有解析替换掉,还是原样保留,比如定义了 |
这些属于 tsc 的编译项的问题,建议找 typescript 的文档 |
@Lellansin 查看了 tsconfig-paths/register 的 issue 发现 tsc 不支持相关转换😰😰😰 |
想问下为什么 dev 期间使用 ts-node,而 build 却使用 tsc 呢? |
开发期间,不需要编译,方便开发调试,而上线了就需要build,走编译后的js文件。ts-node 本身性能不是很高,只能用于开发环境。 |
更新:折腾了下,根据 tsconfig-paths 的文档,单独开了个文件来使用 tsconfig-paths 的 register, 用于别名路径解析,然后
因为不知道 egg-scripts 怎么给 node 传递参数,所以改用 pm2 做部署监控了,这个问题 nestjs 也有,解决的方案一样,有些好奇大佬们开发的时候都不使用路径别名的吗? |
我个人一般不用。。。 |
使用midway-init才新建的工程,运行npm run build报错
The text was updated successfully, but these errors were encountered: