babel-node should add '.ts', '.tsx' as a default extensions to hook into
See original GitHub issueBug Report
Current Behavior
I’m running jasmine tests in babel-node in my front-end typescript project, and I got
SyntaxError: Cannot use import statement outside a module
It took me four hours to understand that *.ts files aren’t included by default in babel-node. Google/SE was no help.
As Typescript is supported by babel since a while back, it seems resonable that babel-node should hook into ‘.ts’-files by default? Perhaps ‘.tsx’ too.
See https://babeljs.io/docs/en/next/babel-node.html
Input Code DOESN’T WORK package.json:
"scripts": {
"test": "npx babel-node spec/run.ts",
},
DOES WORK package.json:
"scripts": {
"test": "npx babel-node -x '.ts' spec/run.ts",
},
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
babel/preset-typescript
Indicates that every file should be parsed as TS, TSX, or as TS without JSX ambiguities (depending on the isTSX and disallowAmbiguousJSXLike options)....
Read more >Running Typescript programs with babel-node aka how does ...
Running Typescript programs on demand with babel-node basically uses ... and Typescript with React, you'll have to add the "extensions" .
Read more >babel-node with typescript throws "Cannot use import ...
I painstakingly converted my babel config to JSON and that seems to have fixed. Also, the --extensions argument must include .ts . So...
Read more >Code Transformation - Jest
?$/ RegExp (in other words, any .js , .jsx , .ts or .tsx file). In addition, babel-jest will inject ...
Read more >unknown file extension .tsx - You.com | The AI Search Engine ...
My tests are written in typescript and all works fine, now I want to have a globalSetup ... even if I try to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I edited the comment above several times.
@dilyanpalauzov no. It’s what @nicolo-ribaudo ref’ed…