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 error with imported variables #855

Closed
kinetifex opened this issue Oct 19, 2021 · 3 comments · Fixed by #874
Closed

Webpack error with imported variables #855

kinetifex opened this issue Oct 19, 2021 · 3 comments · Fixed by #874
Labels
bug report 🦗 Issue is probably a bug, but it needs to be checked bundler: webpack 📦 Issue is related to webpack bundler needs: complete repro 🖥️ Issue need to have complete repro provided

Comments

@kinetifex
Copy link
Contributor

kinetifex commented Oct 19, 2021

Environment

  • Linaria version: 3.0.0-beta.13
  • Bundler (+ version): webpack@5.59.0
  • Node.js version: 14.15.1
  • OS: macOS@11.6

Description

We've been using Linaria successfully in our projects for a while now. However, I have encountered a strange issue recently with using the Webpack loader, but which works with CLI.

If I use a constant that is imported from another module, Webpack blows up with finishWithoutResolve error.

For example:

import { styled } from '@linaria/react';
import { device, size } from './breakpoints';

const Description = styled.p`
  background-color: orange;
 
  @media ${ device.tablet } {    
    background-color: blue;
  }
`;

Fails to build, erroring with:
Can't resolve './breakpoints' in '/path/to/linaria-webpack-bug/src'

Reproducible Demo

A reproducible repo with steps is available here:
https://github.com/kinetifex/linaria-webpack-bug

@kinetifex kinetifex added bug report 🦗 Issue is probably a bug, but it needs to be checked needs: complete repro 🖥️ Issue need to have complete repro provided needs: triage 🏷 Issue needs to be checked and prioritized labels Oct 19, 2021
@github-actions github-actions bot added bundler: webpack 📦 Issue is related to webpack bundler and removed needs: triage 🏷 Issue needs to be checked and prioritized labels Oct 19, 2021
@kinetifex
Copy link
Contributor Author

So, the root of the problem is the missing extension in the import. The enhanced resolve doesn't know how to find it. It appears that the default resolve option extensions were dropped in this #830.

A few options for this fix:

  1. Update all import paths to include the extension (i.e. ./breakpoints.js)
  2. Set the resolve.extensions in the webpack config
  3. Set the resolveOptions.extensions for the Webpack loader options.

@kinetifex
Copy link
Contributor Author

kinetifex commented Oct 20, 2021

Re-opening this as my work-around 👆🏻 really shouldn't be required for basic configs. The resolve.extensions and conditionNames would still benefit from having defaults, at best utilizing the defaults from Webpack itself (docs).

@kinetifex kinetifex reopened this Oct 20, 2021
Anber added a commit that referenced this issue Nov 28, 2021
…#874)

* fix(webpack): fallback to default resolver if async plugin is detected
* fix(webpack): don't use default extensions if it's empty (fixes #855)
@Anber
Copy link
Collaborator

Anber commented Nov 28, 2021

Hi @kinetifex!

I think it's happened because the default value for extensions is an empty array, which is replaced with the default list of extensions somewhere inside Webpack. I've added a workaround for that case. I hope it'll help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report 🦗 Issue is probably a bug, but it needs to be checked bundler: webpack 📦 Issue is related to webpack bundler needs: complete repro 🖥️ Issue need to have complete repro provided
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants