Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot compile modules using option 'outFile' unless the '--module' flag is 'amd' or 'system'

I'm building a Node-Mongodb server with Typescript and getting this error on build:

[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

Here's my tsconfig.json:

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


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

I'm using gulp-typescript to run this task. Here's my configuration:

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

Thanks.

like image 488
Pistolpete . Avatar asked Feb 13 '18 13:02

Pistolpete .


2 Answers

I had the same error using gulp to compile typescript to js in Visual Studio 2017. My solution was to not use the outFile option without the module: "system" option (see first option https://github.com/ivogabe/gulp-typescript).

My setup: Visual Studio 2017 15.7.4 packages.json > "gulp-typescript": "4.0.2", "typescript": "2.8.4", "@types/jquery": "3.3.4"

typescript compile task in gulpfile.js

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

When using outFile: output without module: "system" I got the error: Scripts\Test.ts(1,1): error TS6131: Cannot compile modules using option 'outFile' unless the '--module' flag is 'amd' or 'system'.

like image 105
mortenma71 Avatar answered Nov 12 '22 22:11

mortenma71


Just for others searching for an answer if other info above does not help.

You might try

//import a from './a';
//import b from './b';

namespace myproject
export class myclass {
   a,
   b
};
}

where 'a' and 'b' are in that namespace , or import them.

I was working on this for several hours - I hope this helps someone!

like image 2
Ken Avatar answered Nov 12 '22 22:11

Ken