This is the default tsconfig.json
file that was generated automatically by Next.js
.
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext", // <=== THIS IS THE PROBLEM
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
My problem with it is that I run some scripts across my project, and I use ts-node
to run them.
I was getting all sorts of errors when trying to run scripts that had some imports on them.
For example:
import fs from "fs";
console.log("HERE");
I was getting: Unexpected token export
And I noticed that if make the following change to tsconfig.json
"module": "esnext", // DELETE THIS LINE
"module": "commonjs" // ADD THIS LINE
Now the script runs fine.
QUESTION
I don't want to mess with the tsconfig.json
that was auto generated by Next.js
. Is it ok to make that change? Am I breaking or risking to break something? Should I create a different tsconfig.json
file? What is the best option here?