Comments (8)
In browsers/Node.js import.meta.resolve
takes a single parameter, so you don't really "notice" that the parent is the file URL and not the folder URL.
from import-meta-resolve.
https://github.com/nodejs/node/blob/1b60054fffc0c67a711cdf3efbcc8f44afab0ce2/lib/repl.js#L461
pathToFileURL(path.join(process.cwd(), 'repl'))
, apparently
from import-meta-resolve.
IMO this is all more about how URLs resolve. Where <a href="x">
goes to. I donβt see the web changing that. It depends on whether youβre on https://example.com/y
or https://example.com/y/
:
new URL('x', 'https://example.com/y').href // 'https://example.com/x'
new URL('x', 'https://example.com/y/').href // 'https://example.com/y/x'
process.cwd
You can solve it with url.pathToFileURL(process.cwd() + path.sep)
.
Anyway, this is a copy of Node. Changes go in Node.
In browsers/Node.js import.meta.resolve takes a single parameter, so you don't really "notice" that the parent is the file URL and not the folder URL.
β @nicolo-ribaudo
Small nit: they do accept a second parameter. They default to import.meta.url
but you can pass any URL. That is impossible to polyfill, so it must be passed explicitly here.
from import-meta-resolve.
Supporting both folders and files as the base is ambiguous: if both foo/index.js
and foo/bar/index.js
exist, what does resolve("./index.js", "foo/bar")
resolve to?
The readme currently says that the second parameter is "the absolute parent module URL", maybe it should either be made more prominent or more explicit that a module is a file π€
from import-meta-resolve.
I don't see how this issue is here?
Anyway, yeah, its the same as browsers. It matters where you resolve from
from import-meta-resolve.
I don't see how this issue is here?
Right this is maybe out of place π€ However, the description is "Resolve things like Node.js.", but when I fire up a REPL and import something what file is Node resolving things from?
from import-meta-resolve.
I think youre looking for import.meta.url? Thats whats also in the docs here as a recommendation.
In ESM i always use that; basically never process.cwd
from import-meta-resolve.
@wooorm yeah but the REPL is a weird environment:
![Screen Shot 2023-12-12 at 18 37 36](https://private-user-images.githubusercontent.com/1812093/289953916-75d5ea98-ed6d-4d54-9ee8-e55cf39cda89.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE2MzU0MjEsIm5iZiI6MTcyMTYzNTEyMSwicGF0aCI6Ii8xODEyMDkzLzI4OTk1MzkxNi03NWQ1ZWE5OC1lZDZkLTRkNTQtOWVlOC1lNTVjZjM5Y2RhODkucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcyMiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MjJUMDc1ODQxWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9M2Y3NGE3ZDFhYTBjZGI2ZTM0MTg0MjQ5MmE3YzMwNDgwZjI2YWMxNmZhN2I2NTQyYjkwNDEyZGVhYzcxZDZjOCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.XO7zHXwJo3nwlo1U2IG-2vecCc2qH5RUU02RUPLg2yg)
Anyway, closing this to keep things tidy. Worth thinking about special-casing what happens if the input path is a folder for convenience, either by throwing with a more specific reason or by doing something else, imo.
process.cwd()
is needed in situations where for example you need to load some plugins, like you do prettier --plugin whatever
, and that whatever
plugin should be loaded from the process.cwd()
basically.
from import-meta-resolve.
Related Issues (18)
- Issues with loading from ESM, "type": "module", & rollup HOT 2
- Enabling usage of this package in an eslint plugin HOT 8
- Support for TypeScript files HOT 13
- Use module.builtinModules instead of builtins dependency HOT 1
- how to resolve named exports? HOT 5
- 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
- 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
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.