Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/fresh-cars-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@vanilla-extract/webpack-plugin': patch
'@vanilla-extract/next-plugin': patch
---

Fix `require is not defined` error in ESM bundles by calling `createRequire`
3 changes: 3 additions & 0 deletions packages/next-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import type {
NextConfig,
WebpackConfigContext,
} from 'next/dist/server/config-shared';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);

type PluginOptions = ConstructorParameters<typeof VanillaExtractPlugin>[0];

Expand Down
3 changes: 3 additions & 0 deletions packages/webpack-plugin/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import {
import type { LoaderContext } from './types';
import { debug, formatResourcePath } from './logger';
import { ChildCompiler } from './compiler';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);

const virtualFileLoader = require.resolve(
path.join(
Expand Down
3 changes: 3 additions & 0 deletions packages/webpack-plugin/src/next.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import path from 'path';
import { AbstractVanillaExtractPlugin } from './plugin';
import type { Compiler } from 'webpack';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);

const virtualNextFileLoader = require.resolve(
path.join(
Expand Down
4 changes: 4 additions & 0 deletions packages/webpack-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import type { Compiler, RuleSetRule } from 'webpack';
import { ChildCompiler } from './compiler';
import createCompat, { type WebpackCompat } from './compat';

import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);

const pluginName = 'VanillaExtractPlugin';

function markCSSFilesAsSideEffects(compiler: Compiler, compat: WebpackCompat) {
Expand Down