Cannot run ts-node inside Angular project root folder.
This error happens:
import { parse } from 'papaparse';
^
SyntaxError: Unexpected token {
It's something with the tsconfig.json file most likely. I already reported the same issue against ng-packagr.
Outside of Angular the code runs fine, even with any tsconfig at all.
This is because the module in the standard tsconfig.json that comes from a new CLI application is set to esnext.
E.g.
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"lib": [
"es2018",
"dom"
]
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
}
}
If you set it to commonjs then ts-node will run the code fine. E.g.
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "commonjs",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"lib": [
"es2018",
"dom"
]
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
}
}
If you don't want to change the default tsconfig.json file then you can tell ts-node to use a different one with the --project flag.
This is not a problem with the Angular framework. If anything you should take it up with the CLI team, but I suspect that this issue will be closed with "works as expected".
Hi @fireflysemantics, as @petebacondarwin explained this is working as expected.
ES modules are not supported by default in Node versions < 14, thus you'd need to create a new tsconfig that uses CommonJS as module and provide it to ts-node via the --project option.
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
_This action has been performed automatically by a bot._
Most helpful comment
This is because the
modulein the standardtsconfig.jsonthat comes from a new CLI application is set toesnext.E.g.
If you set it to
commonjsthen ts-node will run the code fine. E.g.If you don't want to change the default
tsconfig.jsonfile then you can tell ts-node to use a different one with the--projectflag.This is not a problem with the Angular framework. If anything you should take it up with the CLI team, but I suspect that this issue will be closed with "works as expected".