I wanted to know a bit more about typescript and wanted to do a small project with it.
I'm running into an error when running the command "tsc app.ts"
1 import express from "express";
~~~~~~~
../node_modules/@types/express/index.d.ts:133:1
133 export = e;
~~~~~~~~~~~
This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.
However I found that when I include the esModuleInterop flag in the tsc command tsc app.ts --esModuleInterop && node app.js - it runs.
I wanted to understand why this was the difference - in the tsconfig.json file I have that flag set to true as well. Was it something that I messed up when setting up typescript?
Below is the tsconfig.json and the package.json file
tsconfig.json:
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
Package.json
{
"name": "restapi",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@types/body-parser": "^1.19.2",
"@types/express": "^4.17.13",
"body-parser": "^1.19.1",
"express": "^4.17.2",
"nodemon": "^2.0.15"
},
"devDependencies": {}
}
tsc app.jsit ignores the tsconfig file. So then we should be compiling with justtscand that's it