Reputation: 4297
I am writing an import statement import { PI } from './math/circle'
in app.ts file and have a constant export const PI = 3.14
in circle.ts file but on running the program by doing tsc app.ts --outFile app.js
keeps showing this error.
error TS6131: Cannot compile modules using option 'outFile' unless the '--module' flag is 'amd' or 'system'. 1 export const PI = 3.14
But according to the docs I am importing correctly. I have also tried changing the "module": "commonjs" to "module": "amd"/"system" and then reloading the VSCode windows but no luck. Where am I going wrong?
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "amd",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictPropertyInitialization": false
},
"exclude": [
"node_modules"
]
}
P.S: typescript version 3.5.3
Upvotes: 14
Views: 12948
Reputation: 2018
You should be using a tool like webpack to bundle multiple typescript files into a single javascript file.
Upvotes: 1
Reputation: 154
If you want your tsconfig.json
to be taken into account you have to invoque the tsc command with no input files, more details here.
Running tsc app.ts --outFile app.js
you are skipping your tsconfig.json
and therefore you have to specify the module system manually so running tsc app.ts --outFile app.js --module amd
should do the trick.
The other option as mentioned above is just to run tsc --outFile app.js
.
Upvotes: 3