[unit
我收到此错误:
D:\nginx\ibdrweb\webapps\ibdr-document-2\doc-app\sources\forms\dynamic-form\lus\lus.js:1
import { Tools } from "@ShareUtils/tools";
^
SyntaxError: Unexpected token {
at Module._compile (internal/modules/cjs/loader.js:721:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
当我尝试执行以下命令时:
ts-mocha -p doc-app/tests/tsconfig.json doc-app/tests/lus-tests.ts
此问题在此处,已关闭。尝试在tsconfig.json上更改“ module”:“ commonjs”无效。很多人写道问题仍然存在]。
我的项目看起来像这样
|- doc-app | |- < many direcotiries used at tests.ts > | |- tests | lus-tests.ts | tsconfig.json | |- node_modules |- tsconfig.json
注意:节点“ v10.16.0”
tsconfig.json 在测试目录中
{ "compilerOptions": { "target": "es5", "declaration": true, "module": "commonjs", "moduleResolution": "node", "sourceMap": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "removeComments": false, "noImplicitAny": false, "suppressImplicitAnyIndexErrors": true, "lib": ["es6", "dom"], "typeRoots": [ "node_modules/@types" ] }, "awesomeTypescriptLoaderOptions": { "useWebpackText": true, "useTranspileModule": true, "doTypeCheck": true, "forkChecker": true }, "include": [ "./" ], "exclude": [ "node_modules" ] }
package.json的有用部分
"devDependencies": { "@types/chai": "4.1.7", "@types/mocha": "5.2.7", "@types/sinon": "7.0.13", ... "chai": "4.2.0", ... "mocha": "6.1.4", ... "sinon": "7.3.2", ... "ts-mocha": "6.0.0", "ts-node": "8.4.1", "typescript": "2.9.2", //if change it to "3.6.3" it dosen't help }
如果我在tsconfig.json中指定“ module”:“ exnext”,则错误为
从“ @ ShareUtils / tools”导入{工具}; node_modules中的模块“工具”D:\nginx\ibdrweb\webapps\ibdr-document-2\doc-app\tests\lus-tests.ts:1 import "mocha"; ^^^^^^^ SyntaxError: Unexpected string at Module._compile (internal/modules/cjs/loader.js:721:23)
[注:
我收到此错误:D:\ nginx \ ibdrweb \ webapps \ ibdr-document-2 \ doc-app \ sources \ forms \ dynamic-form \ lus \ lus.js:1从“ @ ShareUtils /工具”; ^ SyntaxError:意外令牌{at ...
回答如下:第一个错误是因为TypeScript未编译您的JavaScript。您将需要能够allowJs
使该文件正常工作。第二个错误是有道理的,当您从CommonJS更改模块输出时,node.js无法理解您的ES模块代码。
[unit
我收到此错误:
D:\nginx\ibdrweb\webapps\ibdr-document-2\doc-app\sources\forms\dynamic-form\lus\lus.js:1
import { Tools } from "@ShareUtils/tools";
^
SyntaxError: Unexpected token {
at Module._compile (internal/modules/cjs/loader.js:721:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
当我尝试执行以下命令时:
ts-mocha -p doc-app/tests/tsconfig.json doc-app/tests/lus-tests.ts
此问题在此处,已关闭。尝试在tsconfig.json上更改“ module”:“ commonjs”无效。很多人写道问题仍然存在]。
我的项目看起来像这样
|- doc-app | |- < many direcotiries used at tests.ts > | |- tests | lus-tests.ts | tsconfig.json | |- node_modules |- tsconfig.json
注意:节点“ v10.16.0”
tsconfig.json 在测试目录中
{ "compilerOptions": { "target": "es5", "declaration": true, "module": "commonjs", "moduleResolution": "node", "sourceMap": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "removeComments": false, "noImplicitAny": false, "suppressImplicitAnyIndexErrors": true, "lib": ["es6", "dom"], "typeRoots": [ "node_modules/@types" ] }, "awesomeTypescriptLoaderOptions": { "useWebpackText": true, "useTranspileModule": true, "doTypeCheck": true, "forkChecker": true }, "include": [ "./" ], "exclude": [ "node_modules" ] }
package.json的有用部分
"devDependencies": { "@types/chai": "4.1.7", "@types/mocha": "5.2.7", "@types/sinon": "7.0.13", ... "chai": "4.2.0", ... "mocha": "6.1.4", ... "sinon": "7.3.2", ... "ts-mocha": "6.0.0", "ts-node": "8.4.1", "typescript": "2.9.2", //if change it to "3.6.3" it dosen't help }
如果我在tsconfig.json中指定“ module”:“ exnext”,则错误为
从“ @ ShareUtils / tools”导入{工具}; node_modules中的模块“工具”D:\nginx\ibdrweb\webapps\ibdr-document-2\doc-app\tests\lus-tests.ts:1 import "mocha"; ^^^^^^^ SyntaxError: Unexpected string at Module._compile (internal/modules/cjs/loader.js:721:23)
[注:
我收到此错误:D:\ nginx \ ibdrweb \ webapps \ ibdr-document-2 \ doc-app \ sources \ forms \ dynamic-form \ lus \ lus.js:1从“ @ ShareUtils /工具”; ^ SyntaxError:意外令牌{at ...
回答如下:第一个错误是因为TypeScript未编译您的JavaScript。您将需要能够allowJs
使该文件正常工作。第二个错误是有道理的,当您从CommonJS更改模块输出时,node.js无法理解您的ES模块代码。