-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
Heroicons package stopped working in tests #54038
Comments
I think it's related to this PR: https://github.com/vercel/next.js/pull/53902/files |
Very strange as this works in a regular Next.js application, so probably |
Maybe it’s because it points to the esm version? Related: |
Experiencing a similar issue now with |
Glad to see that I'm not the only one, I lost several hours trying to solve this bug but couldn't find a solution. |
Same issue with lucide-react in this closed - but not solved - issue: #53668 |
) ## Initial Pass The initial pass applies to all user code. If an import (`foo`) matches one of the packages from our list, say: ```js // user code import { a } from 'foo' import { otherThings } from './code' ``` The initial pass transforms it into: ```js // user code import { a } from '__barrel_optimize__?names=a!=!foo' import { otherThings } from './code' ``` ## Barrel Optimizations This `__barrel_optimize__` loader is used to optimize the imports of "barrel" files that have many re-exports. Currently, both Node.js and Webpack have to enter all of these submodules even if we only need a few of them. For example, say a file `foo.js` with the following contents: ```js export { a } from './a' export { b } from './b' export { c } from './c' ... ``` If the user imports `a` only, this loader will accept the `names` option to be `['a']`. Then, it request the `__barrel_transform__` SWC loader to load `foo.js` (via `this.loadModule` Webpack API) and receive the following info: ```js export const __next_private_export_map__ = '[["./a","a","a"],["./b","b","b"],["./c","c","c"],...]' ``` The export map, generated by SWC, is a JSON that represents the exports of that module, their original file, and their original name (since you can do `export { a as b }`). Then, this loader can safely remove all the exports that are not needed and re-export the ones from `names`: ```js export { a } from './a' ``` That's the basic situation and also the happy path. ## Wildcard Exports For wildcard exports (e.g. `export * from './a'`), it becomes a bit more complicated. Say `foo.js` with the following contents: ```js export * from './a' export * from './b' export * from './c' ... ``` If the user imports `bar` from it, SWC can never know which files are going to be exporting `bar`. So, we have to keep all the wildcard exports and do the same process recursively. This loader will return the following output: ```js export * from '__barrel_optimize__?names=bar&wildcard!=!./a' export * from '__barrel_optimize__?names=bar&wildcard!=!./b' export * from '__barrel_optimize__?names=bar&wildcard!=!./c' ... ``` The "!=!" tells Webpack to use the same loader to process './a', './b', and './c'. After the recursive process, the "inner loaders" will either return an empty string or: ```js export * from './target' ``` Where `target` is the file that exports `bar`. ## Non-Barrel Files If the file is not a barrel, we can't apply any optimizations. That's because we can't easily remove things from the file. For example, say `foo.js` with: ```js const v = 1 export function b () { return v } ``` If the user imports `b` only, we can't remove the `const v = 1` even though the file is side-effect free. In these caes, this loader will simply re-export `foo.js`: ```js export * from './foo' ``` Besides these cases, this loader also carefully handles the module cache so SWC won't analyze the same file twice, and no instance of the same file will be accidentally created as different instances. --- - [x] Disable this loader for Jest - [x] Add tests for SWC loader caching - [x] Add tests for external modules - [x] Add tests for pages - [x] Add tests for recursive `export *`s --- Closes #54038, closes #54286.
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 22.6.0: Wed Jul 5 22:22:05 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6000 Binaries: Node: 18.14.0 npm: 8.19.3 Yarn: 1.22.19 pnpm: 8.6.12 Relevant Packages: next: 13.4.16 eslint-config-next: 13.4.16 react: 18.2.0 react-dom: 18.2.0 typescript: 4.9.5 Next.js Config: output: N/A
Which area(s) of Next.js are affected? (leave empty if unsure)
Jest (next/jest)
Link to the code that reproduces this issue or a replay of the bug
n/a
To Reproduce
Describe the Bug
After upgrading to 13.4.16 from 13.4.13 my unit tests stopped working for any test cases that test components that use the
@heroicons/react
-package with the error:app:test: Cannot find module '@heroicons/react/20/solid/esm/Squares2X2Icon' from 'src/layouts/WrapperLayout.tsx'
Expected Behavior
I would expect that the unit tests to pass
Which browser are you using? (if relevant)
Edge
How are you deploying your application? (if relevant)
Other platform
NEXT-1517
The text was updated successfully, but these errors were encountered: