Comments (8)
I recently wanted to add this package as a dependency of Babel, and we are probably going to inline it in our source code so that we can compile it to CJS until we are ready to migrate to ESM: https://github.com/babel/babel/pull/14110/files#diff-754bd25a9bce7737d21fa0a30ade059884e89f9e4298c6c16ee25ad4b21e7651R531
@giltayar Maybe you could do something similar?
An alternative is to do something like https://giuseppegurgone.com/synchronizing-async-functions/ so that you can use dynamic import to load this package and also use the async resolution algorithm, while still being able to use it in a (cjs, sync) ESLint plugin. We do something similar in @babel/eslint-parser
: ESLint only allows synchronous parser, but we need to run it asynchronously so we moved it to a separate worker (babel/babel#13199).
from import-meta-resolve.
Hey both!
I think we’ve reached a point where CJS users can create vendored versions of ESM packages they use? E.g.,:
npx esbuild import-meta-resolve --bundle --platform=node --outfile=vendor/import-meta-url.cjs
I think this issue also points to an old problem in esbuild: it should really start supporting async things at some point?
from import-meta-resolve.
It's generally a very bad idea to transpile code one didn't author.
from import-meta-resolve.
@ljharb @wooorm From my point of view this isn't a theoretical discussion. It's a practical one to solve a specific problem I have. And the three suggestions here, from @wooorm and @nicolo-ribaudo, seem like good practical solutions (although the "synchronized worker" sounds a bit too heavy for use in an eslint plugin).
from import-meta-resolve.
What is this nonsense. Esbuild, swc, webpack, whathaveyou disagree.
@ljharb i understand you were pinged but I don't think us having another ESM discussion is fruitful.
from import-meta-resolve.
@wooorm this isn't an ESM discussion, it's a "transpiling has caveats that only the author can understand if they apply or not" discussion. There will never be a point at which that isn't true, because the JS language doesn't permit that confidence.
from import-meta-resolve.
Right, I'm against compiling esm to cjs too?
Though, I assume that an eslint plugin vendoring a dependency with a good amount of tests won't pose any problems?
from import-meta-resolve.
Whether you compile it yourself or not is the ESM discussion we don't have to have :-) I'm saying that if you don't, nobody else should. A good amount of tests wouldn't likely cover all the platforms that are likely to break.
from import-meta-resolve.
Related Issues (18)
- Issues with loading from ESM, "type": "module", & rollup HOT 2
- Yarn PnP compatibility? HOT 18
- Want help on maintenance? HOT 4
- Circular dependency in lib/get-format.js HOT 1
- `import.meta.resolve` is now defined to be _sync_ HOT 1
- Possible to use worker threads and execArgv? HOT 14
- exporting the `packageResolve` function HOT 2
- Support for resolving modules from folder paths HOT 8
- First item is always resolved when export map target is Array (even if non-existent) HOT 8
- Resolve fails on MacOS and Windows, works on linux HOT 7
- Incompatible with yarn P'n'P HOT 12
- unexpected `ERR_PACKAGE_PATH_NOT_EXPORTED` thrown HOT 8
- Make this work with yarn berry (aka yarn 2/3/4) HOT 7
- [DEP0180] DeprecationWarning: fs.Stats constructor is deprecated in Node v22.0.0 HOT 4
- Support for TypeScript files HOT 13
- Use module.builtinModules instead of builtins dependency HOT 1
- how to resolve named exports? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from import-meta-resolve.