-
-
Notifications
You must be signed in to change notification settings - Fork 535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't get simple script to run due to SyntaxError: Unexpected token import #313
Comments
Nevermind, it appears es2015 is not yet supported. |
In case anyone else arrive here, this works: |
Did you manage to get webpack config written in TypeScript to work? Following the webpack documentation on the subject seems to give a |
I think this should be added to README.
Don't want to write stupidly annoying Webpack config at all for just a small script. Otherwise, why use ts-node? |
Prior to TypeScript v4.0.5, I didn't need any special flags to run In order to run the script successfully from within package.json as an
So you have to escape the escape. The first
To run it from the CLI directly rather than as an It took me about an 2 hours messing around to figure this out. Works cross platform on Windows and Linux build agents I hope this note can help someone else. |
In these situations, I recommend using tsconfig.json can be given special, // tsconfig.json
{
"ts-node": {
"transpileOnly": true, // you can specify ts-node options here
"compilerOptions": {
"module": "commonjs" // you can also override compilerOptions. Only ts-node will use these overrides
}
},
"compilerOptions": {
"module": "esnext" // tsc will continue to use these options
}
} |
There's experimental ES Module support now, see here |
Yes, native ES module support will work. Thanks for linking to the docs. However, often people actually want to enable The docs have a breakdown of the differences and configuration examples: Other useful tidbits:Use The latest In rare cases, |
ESM Support: |
Note that the |
commit c0b39da Author: alex <[email protected]> Date: Sun May 1 12:59:12 2022 -0300 added watch mode commit a4b4243 Author: alex <[email protected]> Date: Sun May 1 12:58:54 2022 -0300 valid number solution commit aeac477 Author: alex <[email protected]> Date: Sun May 1 12:58:38 2022 -0300 added logger commit 760dc85 Author: alex <[email protected]> Date: Sun May 1 10:11:47 2022 -0300 Fix from TypeStrong/ts-node#313
For anyone finding this, I ran into the same issue and was able to fix it. |
I hope i'm not just doing something stupid but i have created an extremely simple project just to figure out how to use
ts-node
properly. This is my setup:package.json
tsconfig.json
bin/script.ts
However, when I run
npm run script
, i get this:The text was updated successfully, but these errors were encountered: