无法使用选项' outFile'编译模块。除非' - 模块'旗帜是' amd'或者'系统'

时间:2018-02-13 13:06:07

标签: node.js mongodb typescript

我正在使用Typescript构建Node-Mongodb服务器并在构建时出现此错误:

[14:57:05] Using gulpfile ~/Desktop/mean/gulpfile.js
[14:57:05] Starting 'default'...
[14:57:05] Finished 'default' after 9.48 ms
[14:57:06] Starting 'build'...
server/app.ts(1,1): error TS6131: Cannot compile modules using option 'outFile' unless the '--module' flag is 'amd' or 'system'.
TypeScript: 1 semantic error
TypeScript: emit succeeded (with errors)
[14:57:08] Finished 'build' after 2.17 s

这是我的tsconfig.json

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es6",
        "allowJs": true,
        "noImplicitAny": true,
        "moduleResolution": "node",
        "sourceMap": true,
        "outDir": "dist",
        "baseUrl": "."


    },
    "include": [
        "./server/**/*"
    ],
    "exclude": [
        "node_modules"
    ]
}

我使用gulp-typescript来运行此任务。这是我的配置:

.pipe(ts({ 
    module: "commonjs", 
    noImplicitAny: true, 
    target: "es5", 
    allowJs: true, 
    outDir: "dist", 
    noImplicitAny: true, 
    moduleResolution: "node" 
})

感谢。

3 个答案:

答案 0 :(得分:0)

我在Visual Studio 2017中使用gulp将打字稿编译为js时遇到了相同的错误。 我的解决方案是在没有模块的情况下不使用outFile选项:“ system”选项(请参阅第一个选项https://github.com/ivogabe/gulp-typescript)。

我的设置: Visual Studio 2017 15.7.4 packages.json>“ gulp-typescript”:“ 4.0.2”,“ typescript”:“ 2.8.4”,“ @ types / jquery”:“ 3.3.4”

gulpfile.js中的

typescript编译任务

gulp.src(source)
  .pipe(ts({
    noImplicitAny: true,
    //outFile: output,
    //module: "system"
  }))
.pipe(gulp.dest(destination));

在使用outFile:不带模块“ system”的输出时,出现错误: Scripts \ Test.ts(1,1):错误TS6131:除非“ --module”标志为“ amd”或“ system”,否则无法使用选项“ outFile”编译模块。

答案 1 :(得分:0)

仅供其他人搜索答案,如果上述其他信息无济于事。

您可以尝试

{+50864-02-11T08:00}

其中“ a”和“ b”位于该命名空间中,或将其导入。

我为此工作了几个小时-希望这对某人有帮助!

答案 2 :(得分:0)

您应该使用webpack之类的工具将多个打字稿文件捆绑到一个javascript文件中。