Javascript SyntaxError:在Angular Package Format项目中运行ts节点时出现意外标记{
我正在尝试使用ts节点运行typescript文件。出现一个奇怪的错误:Javascript SyntaxError:在Angular Package Format项目中运行ts节点时出现意外标记{,javascript,angular,typescript,ts-node,angular-package-format,Javascript,Angular,Typescript,Ts Node,Angular Package Format,我正在尝试使用ts节点运行typescript文件。出现一个奇怪的错误: import { tes } from "./tes"; ^ SyntaxError:意外标记{ 在模块处编译internal/modules/cjs/loader.js:720:23 如果我将项目ts文件复制到一个空目录中,并尝试在没有任何配置的情况下运行该文件,那么它工作正常,因此它是配置中的一部分 我还尝试生成一个全新的角度包格式项目: ng new proj --create-applicatio
import { tes } from "./tes";
^
SyntaxError:意外标记{
在模块处编译internal/modules/cjs/loader.js:720:23
如果我将项目ts文件复制到一个空目录中,并尝试在没有任何配置的情况下运行该文件,那么它工作正常,因此它是配置中的一部分
我还尝试生成一个全新的角度包格式项目:
ng new proj --create-application=false
cd proj
ng g library x
如果我删除了所有与项目和库相关联的tsconfig文件,ts节点运行正常。当我将它们保留在中时,我会得到相同的错误
tes文件位于Angular软件包格式库中。这是顶级tsconfig.json:
这是特定于项目的tsconfig.lib.json:
想法?看起来您的tsconfig设置为使用esnext模块输出js,没有配置的节点无法理解这些模块。您可以: 从tsconfig.json中删除模块:esnext,行 或者,假设您希望保留Angular的配置,请通过以下方式将节点配置为使用新的ES模块语法
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"lib": [
"es2018",
"dom"
],
"paths": {
"csv": [
"dist/csv/csv",
"dist/csv"
]
}
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
}
}
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/lib",
"target": "es2015",
"declaration": true,
"inlineSources": true,
"types": [],
"lib": [
"dom",
"es2018"
]
},
"angularCompilerOptions": {
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"enableResourceInlining": true
},
"exclude": [
"src/test.ts",
"**/*.spec.ts"
]
}