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

core-js's use by babel not resolving in workspace modules #947

Closed
1 task
daveisfera opened this issue Feb 13, 2020 · 4 comments
Closed
1 task

core-js's use by babel not resolving in workspace modules #947

daveisfera opened this issue Feb 13, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@daveisfera
Copy link

  • I'd be willing to implement a fix

Describe the bug

I'm trying to use yarn 2 to build an application with webpack and I get this error when building with both webpack 4 and pnp-webpack-plugin and webpack 5:

(node:415) UnhandledPromiseRejectionWarning: Error: Error on webpack build: ../lib/core/lib/nudash.js
Module not found: Error: Something that got detected as your top-level application (because it doesn't seem to belong to any package) tried to access a package that is not declared in your dependencies

Required package: core-js (via "core-js/modules/web.dom-collections.iterator")
Required by: /usr/src/app/lib/core/lib/nudash.js

It appears that the use of core-js that's being done by babel isn't resolving in the workspace modules.

To Reproduce

Use a module in a workspace that is processed by babel where core-js is used

Environment if relevant (please complete the following information):

  • OS: Alpine 3.11
  • Node version: 12.14.1
  • Yarn version: 2.0.0-rc.28
@daveisfera daveisfera added the bug Something isn't working label Feb 13, 2020
@arcanis
Copy link
Member

arcanis commented Feb 13, 2020

As @sokra rightly explained Babel injects core-js in your built files, but you still need to add it explicitly to your owns. Otherwise you would rely on hoisting, which is unsound (there's no telling which version of core-js you'd get depending on the packages that are part of the dependency tree).

@arcanis arcanis closed this as completed Feb 13, 2020
@daveisfera
Copy link
Author

Then why does this work with standard modules? And why can't modules in a workspace work the same way?

@arcanis
Copy link
Member

arcanis commented Feb 13, 2020

Because hoisting made it accidentally work. Yarn 2 makes things stricter and let you know when you're using unsound pattern that will eventually cause problems in your deployment - instead of just letting you think that things are alright until the crash.

@daveisfera
Copy link
Author

Sorry, I understand the difference between yarn 1 and 2 and what's going on there (I actually really like the explicit resolution that's happening with yarn 2).

The injection of core-js by babel into a "standard module" that's listed in package.json and pulled from npm appears to work just fine, so my question is why doesn't it behave the same way and work just like a "standard module" with my "workspace module" that is also listed in package.json?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants