Open heavyk opened 4 years ago
The ES module resolver doesn't support loading "files" in node_modules that aren't within valid package names.
We could certainly improve the error message in this case though.
ok, I updated my original post to add a package.json (so it's a "valid" package).
is there a quick and dirty way (for right now to hack it) so that I can symlink a bunch of files (they all import other files using the @package
name identifier) so that they can be imported? if not, I can just make a rollup build to convert them to cjs, so no big deal.
As I see it, the problem with this is that @
at the beginning of the package name is interpreted as referring to scoped/namespaced package (i.e. https://docs.npmjs.com/about-scopes) and the code is, therefore, searching for full package name (which will always be in the form of @scopename/package
or @scopename/package/file.js
) but since you want to directly read the file from a folder named @package
that doesn't work and it interprets the file as a part of package name.
I don't think there is an easy way to make it work without changing to proper package imports.
Is this still occuring? AFAICT the recommended import errror isn't showing (but just a standard error):
mkdir -p node_modules/@broken_imports
echo 'export const lala = 3' > node_modules/@broken_imports/lala.mjs
echo "import { lala } from '@broken_imports/lala.mjs'" > test_imports.mjs
node test_imports.mjs
echo '{"name": "test-pkg", "type": "module"}' > node_modules/@broken_imports/package.json
node test_imports.mjs
What steps will reproduce the bug?
ok, now, we'll make it a es module package. it'll still say the same error.
How often does it reproduce? Is there a required condition?
always happens for me. should output:
What is the expected behavior?
I expected it to import. the docs say: https://nodejs.org/api/esm.html#esm_no_node_path
tried with symlinks too, and couldn't get it to work.