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

Loading node_modules with import/require #589

Open
nabetti1720 opened this issue Sep 15, 2024 · 2 comments
Open

Loading node_modules with import/require #589

nabetti1720 opened this issue Sep 15, 2024 · 2 comments

Comments

@nabetti1720
Copy link
Contributor

We know that bundling is better for performance, but for experimental or less performance-intensive use cases, it would be great if node_modules loading could be supported.

// index4.js
import { Event } from "event-target-shim";

globalThis.Event = Event

import { Bench } from 'tinybench';

const bench = new Bench({ time: 100 });

import mod from '../package.json';

bench
  .add('json', async () => {
    JSON.stringify(mod)
  })
await bench.warmup();
await bench.run();
console.log(bench.table());
% llrt ./src/index4.js
ReferenceError: Error resolving module 'event-target-shim' from './src/index4.js'
@ahaoboy
Copy link
Contributor

ahaoboy commented Sep 17, 2024

Resolve is very complex, for reference:

https://crates.io/crates/oxc_resolver

https://www.npmjs.com/search?q=enhanced-resolve

@richarddavison
Copy link
Contributor

Yes, agree that this is super useful but also very complex:
ESM: https://nodejs.org/api/esm.html#resolution-and-loading-algorithm
CJS: https://nodejs.org/api/modules.html#all-together

Maybe we should do a basic support that doesn't handle all the edge cases?

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

3 participants