Skip to content

"Uncaught ReferenceError: process is not defined" when importing "tailwindcss/resolveConfig" with Webpack 5 (v3.3.0) #10918

@sgarcia-dev

Description

@sgarcia-dev

What version of Tailwind CSS are you using?

v3.3.0

What build tool (or framework if it abstracts the build tool) are you using?

Webpack 5.77.0

What version of Node.js are you using?

For example: v14.18.1

What browser are you using?

For example: Chrome

What operating system are you using?

For example: macOS (intel=

Describe your issue

After upgrading to tailwind v3.3.0 from v3.2.7 we got this warning at runtime, causing the app to fail from running

sharedState.js:30 Uncaught ReferenceError: process is not defined
    at ./node_modules/tailwindcss/lib/lib/sharedState.js (sharedState.js:30:1)
    at __webpack_require__ (bootstrap:19:1)
    at ./node_modules/tailwindcss/lib/featureFlags.js (featureFlags.js:18:22)
    at __webpack_require__ (bootstrap:19:1)
    at ./node_modules/tailwindcss/lib/util/normalizeConfig.js (normalizeConfig.js:9:23)
    at __webpack_require__ (bootstrap:19:1)
    at ./node_modules/tailwindcss/lib/util/resolveConfig.js (resolveConfig.js:15:26)
    at __webpack_require__ (bootstrap:19:1)
    at ./node_modules/tailwindcss/lib/public/resolve-config.js (resolve-config.js:9:61)
    at __webpack_require__ (bootstrap:19:1)

Screenshot_2023 03 30_11 53 AM

This was caused by one of our components import of import resolveConfig from 'tailwindcss/resolveConfig' with Webpack 5. Which causes the following process.env check to throw a runtime error.

DEBUG: resolveDebug(process.env.DEBUG),

Apparently it's caused by Webpack 5's removal of polyfills.

webpack 5 does no longer include a polyfill for this Node.js variable. Avoid using it in the frontend code.

There are workarounds for this such as including a process polyfill with webpack.DefinePlugin, but I think this should probably not be necessary.

I wonder if this could be fixed by just adding a typeof process !== 'undefined' && before it? We also got this issue as well on upgrading, so maybe they are related? Downgrading for now
#10894

In case its relevant, we're mixing ESM modules with CommonJS, which is also similar in the bug above.

I'm sorry I don't have a runnable example, but I hope this information proves useful to fixing this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions