Skip to content
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

ERR_UNKNOWN_FILE_EXTENSION running a basic ts file? #36

Open
cjroebuck opened this issue Sep 17, 2021 · 8 comments
Open

ERR_UNKNOWN_FILE_EXTENSION running a basic ts file? #36

cjroebuck opened this issue Sep 17, 2021 · 8 comments

Comments

@cjroebuck
Copy link

cjroebuck commented Sep 17, 2021

Not sure what I'm doing wrong but...

node -r esbuild-runner/register helloworld.ts 
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /Users/cjr/dev/packages/api/helloworld.ts
    at new NodeError (node:internal/errors:363:5)
    at Loader.defaultGetFormat [as _getFormat] (node:internal/modules/esm/get_format:71:15)
    at Loader.getFormat (node:internal/modules/esm/loader:105:42)
    at Loader.getModuleJob (node:internal/modules/esm/loader:243:31)
    at Loader.import (node:internal/modules/esm/loader:177:17)
    at Object.loadESM (node:internal/process/esm_loader:68:5)

helloworld.ts:

console.log("HELLO WORLD LITERALLY!");
export default {}
node -v
> v16.3.0
@cjroebuck
Copy link
Author

Should add, this is within an ESM module where "type":"module" is present in package.json.

And tsconfig.json for this is:

{
  "compilerOptions": {
    "moduleResolution": "Node",
    "skipLibCheck": true,
    "lib": ["es2020"],
    "module": "ES2020",
    "target": "es6",
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true
  }
}

@sushruth
Copy link

sushruth commented Nov 25, 2021

I can confirm that this has been happening to me in a yarn workspace as well, even with esr ./my/file.ts

EDIT: I found a repeatable way to repro this in yarn 2+ - if for some reason yarn pnpEnableEsmLoader: true is set in .yarnrx.yml, this always happens. In case this is not set, if @yarnpkg/cli is part of the yarn workspace tree, this happens then as well.

EDIT 2: Turns out, the esm loader is the one that is screwing it up for me. This is what I had to configure in my yarn 2 workspace (.yarnrc.yml) to get esbuild-runner to work -

enableGlobalCache: false
pnpEnableEsmLoader: false

That made esr work for me.

@revmischa
Copy link

I'm getting ERR_UNKNOWN_FILE_EXTENSION as well using esr in my ESM project, using NPM.

@codetheweb
Copy link

https://github.com/antfu/esno seems to work with ES modules.

@marklai1998
Copy link

marklai1998 commented May 24, 2022

why is it still not solved after half a year

@codetheweb
Copy link

Yep, I'm using tsx as well now and it's been working great.

@marklai1998
Copy link

Moved to tsx as well

@Toilal
Copy link

Toilal commented Dec 29, 2022

Did you find a way to add esbuild configuration using tsx ? (something like esbuild-runner.config.js file would be great)

caleb531 added a commit to caleb531/personal-website that referenced this issue Jan 4, 2023
Also had to migrate away from esbuild-runner, since it produces an
'Unknown file extension ".ts"' error when attempting to run the utility
with "type":"module" set in package.json. Per
<folke/esbuild-runner#36 (comment)>,
switching to the tsx (TypeScript Execute) package fixes the ability to
run the utility.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants