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

Webpack 5 support #681

Closed
arendjr opened this issue Oct 12, 2020 · 11 comments
Closed

Webpack 5 support #681

arendjr opened this issue Oct 12, 2020 · 11 comments
Labels
bundler: webpack 📦 Issue is related to webpack bundler enhancement: proposal 💬 Improvement of current behaviour that needs to be discussed needs: triage 🏷 Issue needs to be checked and prioritized

Comments

@arendjr
Copy link

arendjr commented Oct 12, 2020

Describe the enhancement

Webpack 5 was released recently. It would be nice if Linaria supports it out-of-the-box.

Motivation

I have a project that is based on Webpack 4 which also uses Yarn PnP. I'm running into issues there with Linaria as soon as modules containing Linaria tags use imports from other modules. I have tracked this down to enhanced-resolve and I suspect it could be related to #658 as Yarn PnP requires some plugins to work with Webpack 4.

However, Webpack 5 and enhanced-resolve 5 (which go hand-in-hand) support Yarn PnP out-of-the-box. I believe once Linaria supports these, everything should "just work".

Possible implementations

A first step would be upgrading to enhanced-resolve@5. I don't know which other steps are necessary.

Related Issues

@arendjr arendjr added the enhancement: proposal 💬 Improvement of current behaviour that needs to be discussed label Oct 12, 2020
@github-actions github-actions bot added bundler: webpack 📦 Issue is related to webpack bundler needs: triage 🏷 Issue needs to be checked and prioritized labels Oct 12, 2020
@Anber
Copy link
Collaborator

Anber commented Oct 26, 2020

Hi @arendjr
It looks like the support of Webpack 5 introduces a lot of changes and I'm afraid that it will postpone the already drawn-out release.
Our next main goal after 2.0 is splitting linaria to separate packages in order to support different bundlers and environments without excess dependencies in the main package, and the loader for Webpack 5 with yarn pnp support is my personal priority goal :)

@Anber
Copy link
Collaborator

Anber commented Oct 28, 2020

The PR with migration to monorepo #687

@Anber
Copy link
Collaborator

Anber commented Nov 23, 2020

Webpack 5 loader has been published (@linaria/webpack5-loader) but it looks like it wasn't enough for supporting yarn pnp.

@arendjr
Copy link
Author

arendjr commented Nov 23, 2020

Awesome! I just tried upgrading, and indeed I'm running into an issue:

ERROR in ./src/index.tsx
Module build failed (from ./.yarn/$$virtual/@linaria-webpack5-loader-virtual-56c8db5b3e/0/cache/@linaria-webpack5-loader-npm-3.0.0-beta.0-00c2e4bddc-9057e5d341.zip/node_modules/@linaria/webpack5-loader/lib/index.js):
Error: @linaria/babel tried to access @linaria/shaker, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

This is due to PnP indeed, the last line described the issue pretty clearly. I think it should be easily fixable, but it probably requires some careful scanning that since the monorepo migration there are no undocumented dependencies between packages.

I didn't get this error with Linaria 2, which actually makes me a little bit hopeful. It's still possible once the above is fixed that the original enhanced-resolve issue is fixed too :)

@Anber
Copy link
Collaborator

Anber commented Nov 23, 2020

Yep, @linaria/shaker should be added to devDependencies. It's a package with evaluation strategy and I forgot to mention it in the documentation.

@arendjr
Copy link
Author

arendjr commented Nov 23, 2020

Does devDependencies suffice, or should it be dependencies? IIUC, devDependencies wouldn't be installed transitively, which I think is necessary here.

@Anber
Copy link
Collaborator

Anber commented Nov 23, 2020

Only @linaria/core and @linaria/react should be dependencies. The rest of the packages can be dev.

@arendjr
Copy link
Author

arendjr commented Nov 23, 2020

Oh, you mean that's what I should do as a user? I think what Yarn is telling us is that it's the responsibility of the @linaria/babel package to specify its dependencies correctly. Along with @linaria/shaker, these seem to be all missing from the dependencies in its package.json:

  • @babel/plugin-proposal-export-namespace-from
  • @babel/plugin-transform-modules-commonjs
  • @babel/plugin-transform-runtime
  • @babel/runtime
  • babel-plugin-transform-react-remove-prop-types

@arendjr
Copy link
Author

arendjr commented Nov 23, 2020

I think this is also related to #700 .

@Anber
Copy link
Collaborator

Anber commented Nov 23, 2020

It's a tricky part. Since @linaria/shaker is optional and can be replaced in a config with another evaluator, we cannot force users to install it even as a peerDependency. I don't sure yet, but maybe it will be possible to add a better notification about missed strategy package. But for now, you need to add that package as a devDependency to your project.

@arendjr
Copy link
Author

arendjr commented Nov 23, 2020

Alright. I might suggest not using it as a default then, if it requires a package you don't want to force users to install.

That said, I've got everything working with Webpack 5 and PnP now. And Linaria components referencing each other across files works as well now. So I'm all happy! Thanks so much!

@arendjr arendjr closed this as completed Nov 23, 2020
hyf0 referenced this issue in airbnb/goji-js Nov 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bundler: webpack 📦 Issue is related to webpack bundler enhancement: proposal 💬 Improvement of current behaviour that needs to be discussed needs: triage 🏷 Issue needs to be checked and prioritized
Projects
None yet
Development

No branches or pull requests

2 participants