2

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": {}
}
1
  • Found a similar issue to mine - stackoverflow.com/questions/45661027/… -> Basically it looks like when we pass in tsc app.js it ignores the tsconfig file. So then we should be compiling with just tsc and that's it Commented Dec 21, 2021 at 14:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.