Cannot find module 'package.json'
ntrrgc opened this issue · 7 comments
This plugin chokes on imports like this one:
import Bag from "typescript-collections/dist/lib/Bag";
🚨 Could not load commonjs-proxy:
<project>/node_modules/typescript-collections/dist/lib/util.js
(imported by <project>/node_modules/typescript-collections/dist/lib/Dictionary.js):
Cannot find module 'package.json'
typescript-collections
has a package.json, of course.
Thank you for your report.
That's weird, I just tried to bundle this module (typescript-collections
), and I can't reproduce the problem. Can you share your configuration (package.json
, rollup.config.js
)?
If you can't share your configuration, feel free to look at this repository to reproduce the problem: https://github.com/mjeanroy/test-rollup-plugin-license
FWIW, I'm running into this as well, on commonjs-proxy
.
https://github.com/dropbox/dropbox-sdk-js/tree/license. I tried pasting my package.json and rollup.config.js into your test, which just generates an empty dependencies.txt for me.
Could not load commonjs-proxy:/Users/praneshp/code/dropbox-sdk-js/node_modules/base64-js/index.js (imported by /Users/praneshp/code/dropbox-sdk-js/node_modules/buffer/index.js): Cannot find module 'package.json'
Same error occurred for me, I resolved it by re-ordering my rollup plugins.
@Havunen it would be nice if you could tell what you did... Move The plugin license up or down ? After which other plugin ?
Cheers
OK, I got it. The bug was caused by the leading NULL 0x00
Unicode character in front of the path of internal modules, typically added by Babel. So, hooking rollup-plugin-license
before Babel could avoid the issue, but I strongly believe that those cases should be handled properly, because it's a norm wanted by rollup. See rollup/rollup#2121 for some related issues.
I've locally fixed the issue, and I'll try to find the time to do a proper PR.
Cheers!
Thank you very much @GerkinDev for your report. I'm waiting for your PR, but if you don't have enough time, I can fix it myself.