gpt4 book ai didi

node.js - typescript :意外的 token 导入

转载 作者:搜寻专家 更新时间:2023-10-30 20:41:38 25 4
gpt4 key购买 nike

刚开始使用 typescript 。不幸的是,当我尝试构建生产环境时失败了。

首先我跑

tsc

此过程没有任何错误,但是当我尝试运行构建文件时出现导入错误

Node 构建/index.js

我得到的错误如下:

[0] (function (exports, require, module, __filename, __dirname) { import {
[0] ^^^^^^
[0]
[0] SyntaxError: Unexpected token import
[0] at createScript (vm.js:80:10)
[0] at Object.runInThisContext (vm.js:139:10)

下面是我的tsconfig

{
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
],
"compilerOptions": {
"lib": [
"es5",
"es6",
],
"pretty": true,
"target": "es5",
"module": "commonjs",
"outDir": "./build",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true
}
}

我正在使用 Node v8.9.3

最佳答案

如果您使用 TypeORM,您的 ormconfig 可能会出现问题。您的配置文件可能包含类似 src/entities/*.ts 的路径在entity部分。所以它导致需要 *.ts来自您的 src 的文件文件夹,不是来自 dist文件夹。

关于node.js - typescript :意外的 token 导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49209911/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com