Skip to content
This repository has been archived by the owner on Sep 2, 2023. It is now read-only.

Adding a --loader makes extensionless files fail to run #512

Closed
giltayar opened this issue May 8, 2020 · 3 comments
Closed

Adding a --loader makes extensionless files fail to run #512

giltayar opened this issue May 8, 2020 · 3 comments

Comments

@giltayar
Copy link

giltayar commented May 8, 2020

To reproduce:

  1. Generate a runnable extensionless file (let's call it runcjs):
#!/usr/bin/env node

console.log('hello')

(note that the hashbang has nothing to do with it and can be removed. I just found it out because I was trying to run a file in ./node_modules/.bin and those are usually extensionless)

  1. Run it with node:
node ./runcjs

This works!

  1. Now add a loader (empty mjs file):
node --loader=./empty.mjs ./runcjs

This fails with the exception [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension "" for ../runcjs

This was tested with Node v14.2.0.

@ljharb
Copy link
Member

ljharb commented May 8, 2020

I believe this is also nodejs/node#33226 ?

@giltayar
Copy link
Author

giltayar commented May 8, 2020

Yup, sorry. Duplicate. I'll close this. Thanks!

@giltayar giltayar closed this as completed May 8, 2020
@DerekNonGeneric
Copy link
Contributor

DerekNonGeneric commented May 9, 2020

You may be able to do this for now.

node --experimental-specifier-resolution=node --experimental-loader=./empty.mjs ./runcjs

You'll need to do something with that getFormat loader hook though.

// empty.mjs
export async function getFormat(url, context, defaultGetFormat) {
  return {
    format: 'commonjs',
  }
}

This workaround may also be a clue to what's currently bugged too.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants