简体   繁体   中英

Package doesn't relate on its internal node_modules packages dependencies, uses external scope instead

I can't figure out why project dependency babel-polifyll doesn't relate to its internal packages from the own node_modules root (they're present there actually). Instead, it trying to get some dependency packages from the same level as the common project node_modules scope...

I understand that this is not a bug in babel-polifyll , probably something happens in node/yarn environment for sure. Anyway, I can't spot what exactly wrong...

Error: 在此处输入图片说明

Babel-polifyll reqiure imports that links from external scope: 在此处输入图片说明

This is an NPM thing, it by default tries to install all packages at the root level, so dependencies can be shared between components. This way when you build your code, if you have three packages using same component, then you output file will only need to have one copy of the built sub-component in it. This keeps the file size down a lot.

NPM will put a dependancy as a child when two packages require different versions of a library and normally you would never notice when this happens, unless you go looking.

This is great when it works, which it does most of the time, but can be a bit of a pig to sort out when it goes wrong.

I just had a look and the latest version of core-js is v3.2.1, but babel-polyfil requires v2.6.5. So the quick fix might be to force install the older version.

npm i -D core-js@2.6.5

This might break something else, if that happens try doing

rm -rf node-modules package-lock.json
npm i

Hopefully that will the force what ever needs the newer version of core-is to install as a child dep and everything will then work for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM