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

Plugin incompatible with Node.js exports package.json field #104

Closed
ctavan opened this issue May 11, 2020 · 3 comments · Fixed by #119
Closed

Plugin incompatible with Node.js exports package.json field #104

ctavan opened this issue May 11, 2020 · 3 comments · Fixed by #119

Comments

@ctavan
Copy link

ctavan commented May 11, 2020

This plugin tries to resolve the package.json files of processed modules:

const resolved = tryResolve(
`${name}/package.json`,
path.dirname(importer)
);

This breaks with npm modules that make use of the new exports field but do not specify a subpath export for the package.json file.

This issue surfaced in uuidjs/uuid#444

IMO this plugin can no longer expect that every npm module exports the package.json file and the resolver logic has to be adjusted accordingly.

Maybe in

function tryResolve(pkg, importer) {
try {
return relative.resolve(pkg, importer);
} catch (err) {
if (err.code === 'MODULE_NOT_FOUND') return null;
throw err;
}
}

we could add ERR_PACKAGE_PATH_NOT_EXPORTED as an "acceptable" error as well?

@jpaquim
Copy link

jpaquim commented May 18, 2020

I was having the same problem with the uuid package, and implemented this PR #108 as a workaround.

I only saw this discussion afterwards, but it seems like it follows in the direction you mentioned, of making it an acceptable error. I could use some feedback on the actual implementation though, there's probably a better way of getting the resolved file name other than parsing the error message.

ctavan added a commit to ctavan/rollup-plugin-svelte that referenced this issue May 18, 2020
ctavan added a commit to ctavan/rollup-plugin-svelte that referenced this issue May 18, 2020
ctavan added a commit to ctavan/rollup-plugin-svelte that referenced this issue May 19, 2020
@maxdobeck
Copy link

Another example: https://github.com/bvaughn/js-search

[!] (plugin svelte) Error: Package subpath './package.json' is not defined by "exports" in /home/.../node_modules/js-search/package.json

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './package.json' is not defined by "exports" in /home/.../node_modules/js-search/package.json

@zwz
Copy link

zwz commented Jun 28, 2020

And here is another one: marijnh/w3c-keyname#10

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

Successfully merging a pull request may close this issue.

4 participants