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.

Typescript support is broken

See original GitHub issue

What were you expecting to happen?

When I follow the steps outlined in this stack-overflow post, it should allow us to write our gulp files in pure Typescript:

https://stackoverflow.com/a/49849088/1611058

These were steps that used to work back in 2020 but don’t work anymore.

What actually happened?

As sydd’s comment says:

I get SyntaxError: Cannot use import statement outside a module if the project’s type is commonjs and TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" if the project’s type is module

Please give us a sample of your gulpfile

// gulpfile.ts

import gulp from 'gulp'

gulp.task('default', function (done) {
    console.log('test');
    done()
});

Terminal output / screenshots

image

image

Please provide the following information:

  • OS & version: Windows 10 - 20H2
  • node version (run node -v): v12.18.2
  • npm version (run npm -v): 6.14.5
  • gulp version (run gulp -v): CLI version: 2.3.0; Local version: 4.0.2

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
phatedcommented, Aug 26, 2021

Sorry, I thought this was commonly known.

I actually think this comment is more likely to be of a benefit in a vite app: https://github.com/TypeStrong/ts-node/issues/922#issuecomment-673155000 (you can override compiler options specifically only for ts-node)

0reactions
Dan503commented, Aug 25, 2021

This fixed it! 😃

https://github.com/TypeStrong/ts-node/issues/922#issuecomment-667076602

In tsconfig.json you need the following:

{
    "compilerOptions": {
        "module": "commonjs",
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

dodgy TypeScript support (missing/broken type inference)
I have several issues with TypeScript support in PhpStorm, but the biggest problem thus far, is that PhpStorm does not perform the level...
Read more >
TypeScript errors and how to fix them
A list of common TypeScript errors and how to fix them. ... Broken Code ❌ ... If you want to support multiline text,...
Read more >
Promise made and promise broken: TypeScript vs. real life data
That's why the suite is run against a long-ish list of supported TypeScript versions, only then I am reasonably certain that the code...
Read more >
Documentation - TypeScript 3.7
Better Support for never -Returning Functions ... This gave us the opportunity to expand support for another class of ... Broken code, do...
Read more >
JavaScript and TypeScript in Visual Studio | Microsoft Learn
The option to restore to the legacy JavaScript language service is no longer available. Users have the new JavaScript language service out-of- ...
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