You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Import from a package that has cross-fetch as a dependencyimport{FetchDocumentLoader}from"npm:jsonld-context-parser";constloader=newFetchDocumentLoader();
Error message
error: Uncaught Error: Cannot find module 'C:\...\deno\npm\registry.npmjs.org\cross-fetch\3.1.5\polyfill\dist\node-ponyfill.js'. Please verify that the package.json has a valid "main" entry
at tryPackage (deno:ext/node/02_require.js:127:21)
Cause of the error
The cross-fetch polyfill is supposed to be imported as import 'cross-fetch/polyfill'. However, the package does not provide exports field in the root package.json. Instead there is a subfolder named polyfill containing a separate package.json file (https://github.com/lquixada/cross-fetch/blob/main/polyfill/package.json).
When resolving the module, Deno uses an entrypoint from the root package.json file, but also keeps the path to the subfolder in the module name, resulting in final path cross-fetch/3.1.5/polyfill/dist/node-ponyfill.js instead of cross-fetch/3.1.5/dist/node-ponyfill.js.
Possible solutions
Let Deno resolve package.json files from subfolders in npm modules.
Another possibility would be to remap the module using an import map to e.g. an empty module, but it is probably not yet supported with the new npm: specifiers (I wasn't able to make it work).
The text was updated successfully, but these errors were encountered:
@karelklima I just tried the reproduction you provided and I don't get any error thrown (Deno v1.29.1). I believe this has been already fixed. I'm gonna close the issue for now, let me know if you encounter any more problems.
@bartlomieju Thank you for fixing this! I will resume working on the project where I encountered the problem and will let you know if there are any other similar issues.
Popular cross-fetch polyfill NPM package (https://github.com/lquixada/cross-fetch) does not work with with the new npm: specifiers.
Example of code that results in an error
Error message
Cause of the error
The cross-fetch polyfill is supposed to be imported as
import 'cross-fetch/polyfill'
. However, the package does not provideexports
field in the rootpackage.json
. Instead there is a subfolder namedpolyfill
containing a separatepackage.json
file (https://github.com/lquixada/cross-fetch/blob/main/polyfill/package.json).When resolving the module, Deno uses an entrypoint from the root
package.json
file, but also keeps the path to the subfolder in the module name, resulting in final pathcross-fetch/3.1.5/polyfill/dist/node-ponyfill.js
instead ofcross-fetch/3.1.5/dist/node-ponyfill.js
.Possible solutions
package.json
files from subfolders in npm modules.cross-fetch
fixes the issue, but it is probably not happening. There is an open PR from mid-2021: Support native node esm imports lquixada/cross-fetch#111The cross-fetch package is quite a big deal as it has 9.6 million weekly downloads on NPM (react has 15.7 million).
Temporary solution
I have managed to make the package work by modifying its local copy in Deno cache by applying changes contained in the aforementioned PR: https://github.com/lquixada/cross-fetch/pull/111/files
Another possibility would be to remap the module using an import map to e.g. an empty module, but it is probably not yet supported with the new
npm:
specifiers (I wasn't able to make it work).The text was updated successfully, but these errors were encountered: