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

标签 node.js typescript

刚开始使用 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/

相关文章:

javascript - 如何让 AngularJS 文件的 Express 路由正常工作

node.js - ExpressJs、Node Js、Passport - 注销后退按钮

node.js - Express api res.jsonp 返回双回调

node.js - 如何使用nodejs sdk将事件发送到api.ai

javascript - 在类中封装验证方法(Angular)

具有 ECU 的亚马逊 EC2 实例的 node.js 性能

javascript - Typescript - 移相器碰撞重叠功能不起作用

javascript - 在 JavaScript 中实现中国剩余定理

class - 在 Angular 2 和 Ionic 2 中访问整个应用程序的关键数据

javascript - 在 Jest 中用测试覆盖抽象类方法