Comments (7)
Can you reduce this. What values are being passed. Which things exist on disk?
I am on mac, it works.
process.cwd() + '/dummy.js'
seems quite bad on your side. /
doesn’t work on Windows. I’d also guess process.cwd()
to be different across OSes. process.cwd()
typically ends in path.sep
already. path.join(process.cwd(), 'dummy.js')
is how you combine paths in Node.
@ts-expect-error the types are wrong
The types here are not wrong? Your await
is wrong.
from import-meta-resolve.
Yarn pnp linker
This sounds quite likely to be the problem too. The algorithm here is based on how Node/npm work. Yarn intentionally does things differently. Perhaps you can see things posted already in its issue tracker
from import-meta-resolve.
Can you reduce this. What values are being passed. Which things exist on disk?
I am on mac, it works.
process.cwd() + '/dummy.js'
seems quite bad on your side./
doesn’t work on Windows. I’d also guessprocess.cwd()
to be different across OSes.process.cwd()
typically ends inpath.sep
already.path.join(process.cwd(), 'dummy.js')
is how you combine paths in Node.
My first thought was indeed around an issue with cwd, I first changed the code to use path.join
to avoid any such issue, but it didn't change a thing.
Regarding the "dummy.js", my understanding is that they (it's not my code) want to resolve a peer dependency, so they concatenate the current directory with a fictitious filename so the resolver thinks it is working for an actual file.
In the end it passes a path like /home/user/project/dummy.js
and @sveltejs/kit
. The only point I could see being a problem is that the "file" used as reference is not in the "src" folder of the project.
from import-meta-resolve.
Yarn pnp linker
This sounds quite likely to be the problem too. The algorithm here is based on how Node/npm work. Yarn intentionally does things differently. Perhaps you can see things posted already in its issue tracker
I know it behave differently, though it works on my Linux VM, plus when I change the code to use import.meta.resolve
from node it works like a charm on all machines.
from import-meta-resolve.
(it's not my code)
It’s not my code either 😉.
In my experience, based on tests, this project works perfectly in macOS, linux, and windows: https://github.com/wooorm/import-meta-resolve/actions/runs/6734940885.
Now it’s on you to create a reduced test case showing it doesn’t!
Showing which results are generated for macos/windows/linux, and which files exist in those 3 cases, will help.
Regarding the "dummy.js"
It’s because .cwd()
points to a folder.
resolve
works from files.
Folders are also files.
But there are differences in resolving from a
, a/
, and a/b.js
.
plus when I change the code to use import.meta.resolve
I believe there are specific things that yarn does for pnp to hook into import.meta.resolve
. If you search for “yarn pnp import.meta.resolve” you’ll find sveltejs/kit#11578 (comment) for example
from import-meta-resolve.
Okay I thought changing this specific call was a clear enough indicator that the code performed differently on different environments, if you don't feel like looking into it, I'll see if I have some time to create a more "isolated" reproducer.
from import-meta-resolve.
See also #10
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
- 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
- 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.