It seems like the --project and --compilerOptions flags have no effect.
I have a directory structure that looks like this:
project root
- scripts
- exportTranslations.ts
- tsconfig.json
- src
- tscnofig.json
- ...other files
- package.json
I've installed [email protected] globally. (Also tried with 4.1.0 and having the same issue.) I've also installed [email protected] both locally and globally.
I'm trying to use the new esModuleInpterop compiler option, so scripts/tsconfig.json looks like this:
{
"compilerOptions": {
"alwaysStrict": true,
"esModuleInterop": true,
"module": "commonjs",
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noFallthroughCasesInSwitch": true,
"skipLibCheck": true,
"strict": true,
"target": "es2017",
},
"include": [
"**/*.ts"
]
}
exportTranslations.ts looks like this:
import path from "path";
const root = path.dirname(__dirname);
console.log(root);
When I run the command ts-node scripts/exportTranslations.ts --project scripts/tsconfig.json --no-cache, I get this error:
TypeError: Cannot read property 'dirname' of undefined
However, if I copy tsconfig.json from scripts into the root folder, it works fine. Also, if I cd into the scripts folder and run ts-node, it works fine. It seems like ts-node always uses tsconfig.json in the current working directory, and ignores whatever I pass for the --project parameter. Am I doing something wrong?
Other things I've tried that don't work (give the same error):
ts-node scripts/exportTranslations.ts --no-cache --compilerOptions '{"esModuleInterop":true}'
SET TS_NODE_PROJECT=scripts/tsconfig.json
ts-node scripts/exportTranslations.ts --project
ts-node scripts/exportTranslations.ts --no-cache --esModuleInteropIs this a bug? Or how am I supposed to use a tsconfig.json file that's not in the current directory?
Finally figured it out - looks like I need to put the --project parameter BEFORE my input file, i.e.
ts-node --project scripts/tsconfig.json scripts/exportTranslations.ts
Would be nice if ts-node supported arguments after the input file, or at least warns you if you try to put an option like --project after your input file.
That's not possible. Node.js works exactly the same way. I think you're neglecting the common use-case of people using a CLI with their own arguments which may or may not be named the same as ts-node arguments. Feel free to submit a PR if you'd like to clarify this in the documentation.
Most helpful comment
Finally figured it out - looks like I need to put the
--projectparameter BEFORE my input file, i.e.