question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

babel-node should add '.ts', '.tsx' as a default extensions to hook into

See original GitHub issue

Bug 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:open
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
dilyanpalauzovcommented, May 20, 2020

I edited the comment above several times.

0reactions
stnorcommented, May 21, 2020

@dilyanpalauzov no. It’s what @nicolo-ribaudo ref’ed…

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found