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

Linaria crashes when used with MSW 2.x with an error Package subpath './browser' is not defined by "exports" #1381

Open
amanmahajan7 opened this issue Nov 15, 2023 · 2 comments
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

@amanmahajan7
Copy link

Environment

Description

Linaria when use with MSW crashed with this error with the minimal reproducible demo below:

> webpack

assets by status 6.96 KiB [cached] 1 asset
./main.js 39 bytes [built] [code generated] [1 error]

ERROR in ./main.js
Module build failed (from ./node_modules/@linaria/webpack5-loader/lib/index.js):
SyntaxError: C:\Users\amahaj200\GitHub\msw-bug\main.js: Package subpath './browser' is not defined by "exports" in C:\Users\amahaj200\GitHub\msw-bug\node_modules\msw\package.json
  1 |
  2 | import { css } from '@linaria/core';
> 3 | import { setupWorker } from 'msw/browser';
    |          ^^^^^^^^^^^
  4 |
  5 | const myClass = css`
  6 |   color: red;
    at File.buildCodeFrameError (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@babel\core\lib\transformation\file\file.js:205:12)
    at NodePath.buildCodeFrameError (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@babel\traverse\lib\path\index.js:98:21)
    at buildCodeFrameError (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@linaria\babel-preset\lib\utils\getTagProcessor.js:24:17)
    at getTagProcessor (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@linaria\babel-preset\lib\utils\getTagProcessor.js:305:15)
    at processTemplateExpression (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@linaria\babel-preset\lib\utils\processTemplateExpression.js:12:61)
    at Identifier (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@linaria\babel-preset\lib\plugins\preeval.js:33:70)
    at NodePath._call (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@babel\traverse\lib\path\context.js:46:20)
    at NodePath.call (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@babel\traverse\lib\path\context.js:36:17)
    at NodePath.visit (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@babel\traverse\lib\path\context.js:82:31)
    at TraversalContext.visitQueue (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@babel\traverse\lib\context.js:86:16)
    at TraversalContext.visitSingle (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@babel\traverse\lib\context.js:65:19)
    at TraversalContext.visit (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@babel\traverse\lib\context.js:109:19)
    at traverseNode (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@babel\traverse\lib\traverse-node.js:22:17)
    at NodePath.visit (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@babel\traverse\lib\path\context.js:88:52)
    at TraversalContext.visitQueue (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@babel\traverse\lib\context.js:86:16)
    at TraversalContext.visitMultiple (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@babel\traverse\lib\context.js:61:17)
    at TraversalContext.visit (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@babel\traverse\lib\context.js:107:19)
    at traverseNode (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@babel\traverse\lib\traverse-node.js:22:17)
    at NodePath.visit (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@babel\traverse\lib\path\context.js:88:52)
    at TraversalContext.visitQueue (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@babel\traverse\lib\context.js:86:16)
    at TraversalContext.visitMultiple (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@babel\traverse\lib\context.js:61:17)
    at TraversalContext.visit (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@babel\traverse\lib\context.js:107:19)
    at traverseNode (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@babel\traverse\lib\traverse-node.js:22:17)
    at traverse (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@babel\traverse\lib\index.js:52:34)
    at NodePath.traverse (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@babel\traverse\lib\path\index.js:101:24)
    at C:\Users\amahaj200\GitHub\msw-bug\node_modules\@linaria\babel-preset\lib\plugins\preeval.js:31:19
    at EventEmitter.perf (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@linaria\utils\lib\EventEmitter.js:45:20)
    at PluginPass.pre (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@linaria\babel-preset\lib\plugins\preeval.js:30:20)
    at transformFile (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@babel\core\lib\transformation\index.js:73:27)
    at transformFile.next (<anonymous>)
    at run (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@babel\core\lib\transformation\index.js:24:12)
    at run.next (<anonymous>)
    at C:\Users\amahaj200\GitHub\msw-bug\node_modules\@babel\core\lib\transform-ast.js:23:33
    at Generator.next (<anonymous>)
    at evaluateSync (C:\Users\amahaj200\GitHub\msw-bug\node_modules\gensync\index.js:251:28)
    at sync (C:\Users\amahaj200\GitHub\msw-bug\node_modules\gensync\index.js:89:14)
    at stopHiding - secret - don't use this - v1 (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@babel\core\lib\errors\rewrite-stack-trace.js:47:12)
    at Object.transformFromAstSync (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@babel\core\lib\transform-ast.js:43:83)
    at runPreevalStage (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@linaria\babel-preset\lib\transform\generators\transform.js:28:24)
    at C:\Users\amahaj200\GitHub\msw-bug\node_modules\@linaria\babel-preset\lib\transform\generators\transform.js:58:75
    at EventEmitter.perf (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@linaria\utils\lib\EventEmitter.js:45:20)
    at prepareCode (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@linaria\babel-preset\lib\transform\generators\transform.js:58:43)
    at BaseAction.internalTransform (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@linaria\babel-preset\lib\transform\generators\transform.js:91:45)
    at internalTransform.next (<anonymous>)
    at C:\Users\amahaj200\GitHub\msw-bug\node_modules\@linaria\babel-preset\lib\transform\actions\BaseAction.js:66:78
    at EventEmitter.action (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@linaria\utils\lib\EventEmitter.js:25:22)
    at BaseAction.emitAction (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@linaria\babel-preset\lib\transform\actions\BaseAction.js:131:39)
    at nextFn (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@linaria\babel-preset\lib\transform\actions\BaseAction.js:66:32)
    at processNext (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@linaria\babel-preset\lib\transform\actions\BaseAction.js:111:28)
    at Object.next (C:\Users\amahaj200\GitHub\msw-bug\node_modules\@linaria\babel-preset\lib\transform\actions\BaseAction.js:120:9)

webpack 5.89.0 compiled with 1 error in 883 ms

Reproducible Demo

https://github.com/amanmahajan7/msw-bug

  1. Clone the repo above
  2. npm ci
  3. npm run build

exports is defined in package.json
https://github.com/mswjs/msw/blob/main/package.json#L16

@amanmahajan7 amanmahajan7 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 Nov 15, 2023
@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 Nov 15, 2023
@nstepien
Copy link
Contributor

This also happens with Vite.

@ui-youcheng-hsu
Copy link

ui-youcheng-hsu commented Dec 6, 2023

same here with webpack v5

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

No branches or pull requests

3 participants