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
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.
You should be using a tool like webpack to bundle multiple typescript files into a single javascript file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With