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

ReferenceError: module is not defined - tailwind.config.js #1388

Closed
evdama opened this issue Dec 8, 2024 · 3 comments
Closed

ReferenceError: module is not defined - tailwind.config.js #1388

evdama opened this issue Dec 8, 2024 · 3 comments

Comments

@evdama
Copy link

evdama commented Dec 8, 2024

Hi folks,

I'm getting this error trying run pnpm run build (same with npm run build):

sa@Mac: ~/0/edm-maizzle  |master U:1 ✗| node -v
v23.3.0
sa@Mac: ~/0/edm-maizzle  |master ✓| pnpm run build

> @ build /Users/sa/0/edm-maizzle
> maizzle build production

◐ Building...(node:68236) ExperimentalWarning: CommonJS module /Users/sa/0/edm-maizzle/node_modules/.pnpm/[email protected]/node_modules/tailwindcss/lib/lib/load-config.js is loading ES Module /Users/sa/0/edm-maizzle/tailwind.config.js using require().
Support for loading ES Module in require() is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
file:///Users/sa/0/edm-maizzle/tailwind.config.js:2
module.exports = {
^

ReferenceError: module is not defined
    at file:///Users/sa/0/edm-maizzle/tailwind.config.js:2:1
    at ModuleJobSync.runSync (node:internal/modules/esm/module_job:395:35)
    at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:329:47)
    at loadESMFromCJS (node:internal/modules/cjs/loader:1376:24)
    at Module._compile (node:internal/modules/cjs/loader:1528:5)
    at Object..js (node:internal/modules/cjs/loader:1698:10)
    at Module.load (node:internal/modules/cjs/loader:1303:32)
    at Function._load (node:internal/modules/cjs/loader:1117:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)

Node.js v23.3.0
 ELIFECYCLE  Command failed with exit code 1.
sa@Mac: ~/0/edm-maizzle  |master ✓|

My package.json is this

{
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "maizzle serve",
    "build": "maizzle build production"
  },
  "dependencies": {
    "@maizzle/framework": "next",    // 5.0.0-beta.38 atm
    "tailwindcss-preset-email": "latest"
  }
}

and my tailwind.config.js is this

/** @type {import('tailwindcss').Config} */
module.exports = {
  presets: [require("tailwindcss-preset-email")],
  content: ["./src/**/*.html"],
  theme: {
    extend: {
      fontFamily: {
        inter: [
          "Inter",
          "ui-sans-serif",
          "system-ui",
          "-apple-system",
          '"Segoe UI"',
          "sans-serif",
        ],
      },
    },
  },
};

It's a standard setup with no changes to any config files. Any ideas what's causing this? I read the docs as well and module.exports including require() seems to be the correct setting no?

@cossssmin
Copy link
Member

Does it do the same when using npm?

@evdama
Copy link
Author

evdama commented Dec 9, 2024

Yes, same with npm (see above).

@cossssmin
Copy link
Member

Looks like Node 23 now sets the --experimental-require-module flag by default, which is what's causing the error. We'll have to see which way they go with this, it might be removed in the future.

Relevant discussion: npm/cli#7857

We currently only support Active LTS releases, so if you really need that Node version you can use ESM in your Tailwind config.

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

No branches or pull requests

2 participants