Skip to content

Conversation

@Pnlvfx
Copy link
Contributor

@Pnlvfx Pnlvfx commented Jun 7, 2025

The webpack plugin was failing when used with Storybook in Node.js 24 environments due to ESM module resolution. Node.js attempts to execute the code as ESM where 'require' is not defined (reference: storybookjs/storybook#31434).

Edit:

⚠️ CJS Breakage with import.meta Workaround

If someone is experiencing this issue they can use my fork for now.

fix-esm-require

While this PR attempts to fix the ESM require issue in Node 24/ Storybook via createRequire(import.meta.url), it will break CJS environments where import.meta is undefined.

Leaving this open for discussion—please weigh in on tradeoffs.

…s ESM context

The webpack plugin was failing when used with Storybook in Node.js 24 environments due to ESM module resolution. Node.js attempts to execute the code as ESM where 'require' is not defined (reference: storybookjs/storybook#31434).

This fix addresses the compatibility issue by properly handling module imports in ESM contexts. The issue became apparent after:
1. Upgrading to @vanilla-extract/[email protected]
2. Implementing changes from #1597

The solution ensures consistent behavior across both CommonJS and ESM module systems.
@changeset-bot
Copy link

changeset-bot bot commented Jun 7, 2025

🦋 Changeset detected

Latest commit: aa28386

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@vanilla-extract/webpack-plugin Patch
@vanilla-extract/next-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Pnlvfx Pnlvfx changed the title fix(webpack-plugin): fix 'require is not defined' error in Node 24 fix(webpack-plugin): 'require is not defined' error in Node 24 Jun 8, 2025
@askoufis
Copy link
Contributor

@Pnlvfx Thanks for the PR. I think this is the right fix, though there's a few more usages of require.resolve within the webpack and next.js plugins that need addressing. Preconstruct replaces import.meta.url in the CJS bundle with its own shim, so it still works.

I'll push a few more changes to your branch and get this PR merged and released as some of our internal tools are blocked by this bug.

@askoufis askoufis merged commit 7a78ebe into vanilla-extract-css:master Jun 11, 2025
5 checks passed
@Pnlvfx
Copy link
Contributor Author

Pnlvfx commented Jun 11, 2025

@Pnlvfx Thanks for the PR. I think this is the right fix, though there's a few more usages of require.resolve within the webpack and next.js plugins that need addressing. Preconstruct replaces import.meta.url in the CJS bundle with its own shim, so it still works.

I'll push a few more changes to your branch and get this PR merged and released as some of our internal tools are blocked by this bug.

Great, thank you. i'm happy to have contributed to this ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants