Skip to content
Latchkey

Node.js "Cannot read config 'tailwind.config.js'" (ESM) in CI

Tailwind loads its config as a module. If the file uses export default in a CommonJS project (or module.exports under "type": "module"), the loader throws and the build cannot read the config.

What this error means

A build fails while loading tailwind.config.js with a module syntax error. The config looks valid but its module style does not match the package type.

node
Error: Failed to load config "tailwind.config.js"
SyntaxError: Unexpected token 'export'
    at compileFunction (node:vm:360:18)

Common causes

Module style mismatch with package type

A .js config is interpreted per the package type. ESM syntax in a CommonJS package (or the reverse) fails to parse.

How to fix it

Match the config syntax to the package type

Use the module form that matches your package.json type.

tailwind.config.js
// CommonJS project ("type" absent or "commonjs")
module.exports = { content: ['./src/**/*.{ts,tsx}'] };

// ESM project ("type": "module")
export default { content: ['./src/**/*.{ts,tsx}'] };

Force a module style by extension

Use an explicit extension to pin the format regardless of package type.

Terminal
# CommonJS config in an ESM project
mv tailwind.config.js tailwind.config.cjs

How to prevent it

  • Keep config module syntax consistent with the package type.
  • Use .cjs/.mjs extensions to make the format explicit.
  • Run the production build in CI so config-load errors surface early.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →