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

Maximum call stack size exceeded #8582

Closed
adamwathan opened this issue Jun 10, 2022 Discussed in #8578 · 27 comments · Fixed by #8636
Closed

Maximum call stack size exceeded #8582

adamwathan opened this issue Jun 10, 2022 Discussed in #8578 · 27 comments · Fixed by #8636

Comments

@adamwathan
Copy link
Member

Discussed in #8578

Originally posted by jithureddy June 10, 2022
Hi, Please help

Just updated my project to latest "tailwindcss": "^3.1.1" and using create react app setup from here. It was working great with "tailwindcss": "^3.0.4".

tailwind.config.js - 

const deepMerge = require('deepmerge')
const formsPlugin = require('@tailwindcss/forms')
const { fontFamily } = require('tailwindcss/defaultTheme')
const colors = require('./colors')

const uiConfig = {
	content: [
		'node_modules/@mondra/ui-components/dist/index.js',
		'./src/**/*.{html,js,jsx,ts,tsx}',
	],
	theme: {
		colors,
		container: {
			padding: '2rem',
		},
		extend: {
			animation: {
				'fade-in': 'fade-in 200ms ease-in-out',
				overlay: 'overlay 200ms ease-in-out',
				'slide-down': 'slide-down 150ms ease-in',
			},
			boxShadow: {
				focus: '#ffffff 0px 0px 0px 0px, #6366f1 0px 0px 0px 2px, rgba(0, 0, 0, 0.05) 0px 1px 2px 0px',
			},
			gridColumn: {
				'span-13': 'span 13 / span 13',
				'span-14': 'span 14 / span 14',
				'span-15': 'span 15 / span 15',
				'span-16': 'span 16 / span 16',
				'span-17': 'span 17 / span 17',
				'span-18': 'span 18 / span 18',
				'span-19': 'span 19 / span 19',
				'span-20': 'span 20/ span 20',
			},
			height: {
				'app-header': '56px',
				'brand-logo': '150px',
				'card-header': '56px',
			},
			keyframes: {
				'fade-in': {
					'0%': {
						opacity: 0,
					},
					'100%': { opacity: 1 },
				},
				overlay: {
					'0%': {
						opacity: 0,
					},
					'100%': { opacity: 0.75 },
				},
				'slide-down': {
					'0%': {
						opacity: 0,
						transform: 'translateY(-10px)',
					},
					'100%': { opacity: 1, transform: 'translateY(0)' },
				},
			},
			maxHeight: {
				'dropdown-list': '40vh',
				'scroll-height': 'calc(100vh - 56px)',
			},
			maxWidth: {
				'company-selection': '150px',
				'sidebar-close': '80px',
				'sidebar-open': '256px',
			},
			minHeight: {
				button: '32px',
				'scroll-height': 'calc(100vh - 56px)',
			},
			minWidth: {
				12: '48px',
				'sidebar-close': '80px',
				'sidebar-open': '256px',
			},
			opacity: {
				80: '0.8',
			},
			screens: {
				xxl: { min: '1600px' },
			},
			spacing: {
				14: '3.5rem',
			},
			width: {
				31: '6rem',
				'brand-logo': '180px',
				'fit-content': 'fit-content',
				'sidebar-close': '80px',
				'sidebar-open': '256px',
			},
			zIndex: {
				'-1': -1,
				dialog: 9999,
				px: 1,
				slideover: 60,
				toast: 10000,
			},
		},
		fontFamily: {
			inter: ['Inter', ...fontFamily.sans],
		},
	},
	plugins: [formsPlugin],
}

function arrayMergeFn(destinationArray, sourceArray) {
	return destinationArray.concat(sourceArray).reduce((acc, cur) => {
		if (acc.includes(cur)) return acc
		return [...acc, cur]
	}, [])
}

/**
 * Merge UI components config and Tailwind CSS configurations
 * @param {object} tailwindConfig - Tailwind config object
 * @return {object} new config object
 */
function wrapper(tailwindConfig) {
	return deepMerge({ ...tailwindConfig }, uiConfig, {
		arrayMerge: arrayMergeFn,
	})
}

module.exports = wrapper
image
@RobinMalfait
Copy link
Contributor

RobinMalfait commented Jun 10, 2022

@jithureddy it looks like you are exporting the wrapper which is a function. This isn't supported and was nog supported in Tailwind 3.0 either.

I'm also confused about why you want to deepMerge the tailwind config in the first place? The extend keyword allows you to merge it with the default config without doing full overrides.

Looking at your config it should suffice to use

module.exports = uiConfig

And drop all of this:

function arrayMergeFn(destinationArray, sourceArray) {
	return destinationArray.concat(sourceArray).reduce((acc, cur) => {
		if (acc.includes(cur)) return acc
		return [...acc, cur]
	}, [])
}

/**
 * Merge UI components config and Tailwind CSS configurations
 * @param {object} tailwindConfig - Tailwind config object
 * @return {object} new config object
 */
function wrapper(tailwindConfig) {
	return deepMerge({ ...tailwindConfig }, uiConfig, {
		arrayMerge: arrayMergeFn,
	})
}

module.exports = wrapper

Can you create a reproduction repo with a working minimal production that showcases the issue?

@jithureddy
Copy link

jithureddy commented Jun 10, 2022

@RobinMalfait Thanks for responding, wrapper is not directly used as tailwind.config.js, the uiConfig exported with wrapper around it from theme-config.js and usage is in the below repo

There are couple projects in which we use the above uiConfig,

Project 1:

const theme = require('@XXX/ui-components/styles/theme-config')
module.exports = theme({
  content: ['./public/index.html'],
  theme: {
    extend: {},
  },
  plugins: [],
})

Project 2

const uiConfig = require('./theme-config')
module.exports = uiConfig({
	plugins: [],
	content: [
		'./node_modules/@XXX/ui-components/dist/index.js',
		'./.storybook/decorator.tsx',
	],
	theme: {
		extend: {},
	},
	variants: {},
})

I can share a repo but that is private repository, thinking how do I put this into github without breaking my company security policies.

@jithureddy
Copy link

@adamwathan We really like tailwindcss and we are using since tailwind v1. We got our own component library using tailwindcss, we even bought tailwindui.com license too. I am really happy that you promoted this help to an issue.

@RobinMalfait I will try to create a repo and share with you soon. But deepMerge was working in 4 projects already with ^tailwindcss:3.0.24

I was working in feature branch, where I had to do eslint and prettier configuration, the repo was working with eslint related fixes and ran npm start and then got the above error. Then I checked out to main stream branch where we had tailwindcss:^3.0.24, did npm install then the app started working.

Again created another feature branch with only tailwindcss:^3.1.2, got the same error. But when I checked out to main branch again, reinstall all node modules, the same error persists.

@eneroth
Copy link

eneroth commented Jun 10, 2022

We're not doing anything in particular to the config, but we're seeing this error as of 3.1.2, as well. The problem is not present in 3.0.24.

@bmichotte
Copy link

I have (nearly) the same issue in my next project after two things :

  1. upgrade to 3.1.2
  2. move the import css files from my app.tsx to my global.css

FYI, here's the screenshot of the revert
CleanShot 2022-06-10 at 19 33 23

The stack is

Failed to compile.

./src/styles/globals.css.webpack[javascript/auto]!=!./node_modules/next/dist/build/webpack/loaders/css-loader/src/index.js??ruleSet[1].rules[3].oneOf[8].use[1]!./node_modules/next/dist/build/webpack/loaders/postcss-loader/src/index.js??ruleSet[1].rules[3].oneOf[8].use[2]!./src/styles/globals.css
RangeError: Maximum call stack size exceeded
    at String.match (<anonymous>)
    at /var/www/project-web/node_modules/tailwindcss/lib/lib/defaultExtractor.js:55:44
    at getClassCandidates (/var/www/project-web/node_modules/tailwindcss/lib/lib/expandTailwindAtRules.js:222:36)
    at /var/www/project-web/node_modules/tailwindcss/lib/lib/expandTailwindAtRules.js:45:13
    at /var/www/project-web/node_modules/tailwindcss/lib/processTailwindFeatures.js:43:53
    at plugins (/var/www/project-web/node_modules/tailwindcss/lib/index.js:30:63)
    at LazyResult.runOnRoot (/var/www/project-web/node_modules/next/node_modules/postcss/lib/lazy-result.js:339:16)
    at LazyResult.runAsync (/var/www/project-web/node_modules/next/node_modules/postcss/lib/lazy-result.js:393:26)
    at LazyResult.async (/var/www/project-web/node_modules/next/node_modules/postcss/lib/lazy-result.js:221:30)
    at LazyResult.then (/var/www/project-web/node_modules/next/node_modules/postcss/lib/lazy-result.js:206:17)

Import trace for requested module:
./src/styles/globals.css
./src/pages/_app.tsx

./src/styles/globals.css
RangeError: Maximum call stack size exceeded
    at String.match (<anonymous>)
    at /var/www/project-web/node_modules/tailwindcss/lib/lib/defaultExtractor.js:55:44
    at getClassCandidates (/var/www/project-web/node_modules/tailwindcss/lib/lib/expandTailwindAtRules.js:222:36)
    at /var/www/project-web/node_modules/tailwindcss/lib/lib/expandTailwindAtRules.js:45:13
    at /var/www/project-web/node_modules/tailwindcss/lib/processTailwindFeatures.js:43:53
    at plugins (/var/www/project-web/node_modules/tailwindcss/lib/index.js:30:63)
    at LazyResult.runOnRoot (/var/www/project-web/node_modules/next/node_modules/postcss/lib/lazy-result.js:339:16)
    at LazyResult.runAsync (/var/www/project-web/node_modules/next/node_modules/postcss/lib/lazy-result.js:393:26)
    at LazyResult.async (/var/www/project-web/node_modules/next/node_modules/postcss/lib/lazy-result.js:221:30)
    at LazyResult.then (/var/www/project-web/node_modules/next/node_modules/postcss/lib/lazy-result.js:206:17)
    at tryRunOrWebpackError (/var/www/project-web/node_modules/next/dist/compiled/webpack/bundle5.js:42028:9)
    at __webpack_require_module__ (/var/www/project-web/node_modules/next/dist/compiled/webpack/bundle5.js:27488:12)
    at __nested_webpack_require_153152__ (/var/www/project-web/node_modules/next/dist/compiled/webpack/bundle5.js:27445:18)
    at /var/www/project-web/node_modules/next/dist/compiled/webpack/bundle5.js:27516:20
    at symbolIterator (/var/www/project-web/node_modules/next/dist/compiled/neo-async/async.js:1:14443)
    at done (/var/www/project-web/node_modules/next/dist/compiled/neo-async/async.js:1:14823)
    at Hook.eval [as callAsync] (eval at create (/var/www/project-web/node_modules/next/dist/compiled/webpack/bundle5.js:141841:10), <anonymous>:15:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/var/www/project-web/node_modules/next/dist/compiled/webpack/bundle5.js:141643:14)
    at /var/www/project-web/node_modules/next/dist/compiled/webpack/bundle5.js:27423:43
    at symbolIterator (/var/www/project-web/node_modules/next/dist/compiled/neo-async/async.js:1:14401)
-- inner error --
RangeError: Maximum call stack size exceeded
    at String.match (<anonymous>)
    at /var/www/project-web/node_modules/tailwindcss/lib/lib/defaultExtractor.js:55:44
    at getClassCandidates (/var/www/project-web/node_modules/tailwindcss/lib/lib/expandTailwindAtRules.js:222:36)
    at /var/www/project-web/node_modules/tailwindcss/lib/lib/expandTailwindAtRules.js:45:13
    at /var/www/project-web/node_modules/tailwindcss/lib/processTailwindFeatures.js:43:53
    at plugins (/var/www/project-web/node_modules/tailwindcss/lib/index.js:30:63)
    at LazyResult.runOnRoot (/var/www/project-web/node_modules/next/node_modules/postcss/lib/lazy-result.js:339:16)
    at LazyResult.runAsync (/var/www/project-web/node_modules/next/node_modules/postcss/lib/lazy-result.js:393:26)
    at LazyResult.async (/var/www/project-web/node_modules/next/node_modules/postcss/lib/lazy-result.js:221:30)
    at LazyResult.then (/var/www/project-web/node_modules/next/node_modules/postcss/lib/lazy-result.js:206:17)
    at Object.<anonymous> (/var/www/project-web/node_modules/next/dist/build/webpack/loaders/css-loader/src/index.js??ruleSet[1].rules[3].oneOf[8].use[1]!/var/www/project-web/node_modules/next/dist/build/webpack/loaders/postcss-loader/src/index.js??ruleSet[1].rules[3].oneOf[8].use[2]!/var/www/project-web/src/styles/globals.css:1:7)
    at /var/www/project-web/node_modules/next/dist/compiled/webpack/bundle5.js:91471:11
    at Hook.eval [as call] (eval at create (/var/www/project-web/node_modules/next/dist/compiled/webpack/bundle5.js:141827:10), <anonymous>:7:1)
    at Hook.CALL_DELEGATE [as _call] (/var/www/project-web/node_modules/next/dist/compiled/webpack/bundle5.js:141639:14)
    at /var/www/project-web/node_modules/next/dist/compiled/webpack/bundle5.js:27490:39
    at tryRunOrWebpackError (/var/www/project-web/node_modules/next/dist/compiled/webpack/bundle5.js:42023:7)
    at __webpack_require_module__ (/var/www/project-web/node_modules/next/dist/compiled/webpack/bundle5.js:27488:12)
    at __nested_webpack_require_153152__ (/var/www/project-web/node_modules/next/dist/compiled/webpack/bundle5.js:27445:18)
    at /var/www/project-web/node_modules/next/dist/compiled/webpack/bundle5.js:27516:20
    at symbolIterator (/var/www/project-web/node_modules/next/dist/compiled/neo-async/async.js:1:14443)

Generated code for /var/www/project-web/node_modules/next/dist/build/webpack/loaders/css-loader/src/index.js??ruleSet[1].rules[3].oneOf[8].use[1]!/var/www/project-web/node_modules/next/dist/build/webpack/loaders/postcss-loader/src/index.js??ruleSet[1].rules[3].oneOf[8].use[2]!/var/www/project-web/src/styles/globals.css

Import trace for requested module:
./src/pages/_app.tsx


> Build failed because of webpack errors
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@adamwathan
Copy link
Member Author

Is anyone able to provide a real reproduction we can clone down and look at? Just the minimum code necessary to trigger this error.

@thecrypticace
Copy link
Contributor

From the stack traces provided this appears to be a regex matching problem. Node is running out of stack space when matching. If anyone can narrow it down to a single file that causes the issue that should be enough to reproduce.

@bmichotte
Copy link

@adamwathan i’ll try to make a reproduction project this weekend

@bmichotte
Copy link

I tried to make a reproduction on https://github.com/bmichotte/tailwindcss-8582 but I can't reproduce...
even on the project I tried yesterday.

It compiles just fine now, on three servers and on local ¯\(ツ)

@radusuciu
Copy link

radusuciu commented Jun 11, 2022

Same issue, attempting repro..

edit: could not reproduce and rolling back to 3.0.24 was not effective. This was on an application (vite/vue3/tailwind) that I haven't developed in 4 months, which worked without issues before. I guess I'll have to strip things down until they work and then build it up until it doesn't - I'll post back but my hunch is that this isn't an issue with tailwindcss on its own, but some combination of packages.

@aliakbarazizi
Copy link

I have same issue but i cant reproduce it

@spdiswal
Copy link

Hi, I managed to trigger the same kind of error in this repository: https://github.com/spdiswal/tailwindcss-8582

@thecrypticace
Copy link
Contributor

@spdiswal Hey! So in your case at least that's an infinite recursion problem and is expected: https://play.tailwindcss.com/1fABzspiRr?file=config — this particular case was an issue in 3.0.24 as well. The fact that it fails on the regex line in your case is, I think, likely a coincidence. It's running into a case of too many recursive function calls.

The problem is that the top-level theme.colors key is defined as a function and inside it the theme is called which looks into the colors object which calls the function when uses the theme function… and repeat to infinity. This is an issue even when using theme.extend.colors.

In your case you probably want to use the provided colors object which references the default color palette:

    colors: ({ colors }) => ({
      foreground: colors.sky['500'],
    }),

Alternatively, if you must use the theme function, you can add your colors to textColor / backgroundColor / etc…:

    textColor: ({ theme }) => ({
      foreground: theme('colors.sky.500'),
    }),

@Crocsx
Copy link

Crocsx commented Jun 14, 2022

I have the same exact issue after updating, I tried to reproduce on a standalone repo, but couldn't... I Will try again later and see if I can get something that reproduce it, but until then, I just wanted to add a comment.

@kisstupid
Copy link

kisstupid commented Jun 14, 2022

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch tailwindcss@3.1.2 for the project I'm working on.

My problem:

Facing RangeError: Maximum call stack size exceeded after some updating in code base.
image

Root cause: using push with too many arguments.
https://stackoverflow.com/questions/42263108/why-does-apply-with-too-many-arguments-throw-maximum-call-stack-size-exceeded

Here is the diff that solved my problem:

diff --git a/node_modules/tailwindcss/lib/lib/defaultExtractor.js b/node_modules/tailwindcss/lib/lib/defaultExtractor.js
index ecb0617..b95200a 100644
--- a/node_modules/tailwindcss/lib/lib/defaultExtractor.js
+++ b/node_modules/tailwindcss/lib/lib/defaultExtractor.js
@@ -52,7 +52,7 @@ function defaultExtractor(context) {
         /** @type {(string|string)[]} */ let results = [];
         for (let pattern of patterns){
             var ref;
-            results.push(...(ref = content.match(pattern)) !== null && ref !== void 0 ? ref : []);
+            results = [...results, ...(ref = content.match(pattern)) !== null && ref !== void 0 ? ref : []];
         }
         return results.filter((v)=>v !== undefined).map(clipAtBalancedParens);
     };

This issue body was partially generated by patch-package.

@jithureddy
Copy link

@adamwathan @RobinMalfait Here is the reproduction repo - https://github.com/jithureddy/tailwind-3.1-template

Thanks.

I will create another reproduction issue where, tailwind css is not working with storybook setup, please see below error. This is essential for us to see all reusable components in action and documented.

image

@jithureddy
Copy link

@adamwathan @RobinMalfait I have created another branch for the above issue when tailwind is used in storybook
https://github.com/jithureddy/tailwind-3.1-template/tree/feature/storybook-tailwind-3.0.24

Interestingly this issue is even persists with tailwindcss:^3.0.24

Steps

  • npm i --legacy-peer-deps
  • npm run storybook

@RobinMalfait
Copy link
Contributor

Hey! Thanks for the reproduction @nam-tran-tego that was exactly the problem!

This should be fixed by #8636, and will be available in the next release (probably later today).

You can already try it by using the insiders build npm install tailwindcss@insiders.


@jithureddy thanks, let's keep the conversation about storybook in its own issue 👍

@jithureddy
Copy link

@RobinMalfait @adamwathan Thanks 👍 both. @nam-tran-tego Thanks for identifying the issue.

The above storybook also works with above insiders build

@eneroth
Copy link

eneroth commented Jun 15, 2022

Looks good in 3.1.3 👍

@radusuciu
Copy link

For me the issue persisted even with 3.1.4 and removing js from the file patterns in tailwind.config.js (see below) fixed it.

# tailwind.config.js
module.exports = {
    content: ["./index.html", "./src/**/*.{vue,js,ts}",],
    theme: {
        extend: {},
    },
    plugins: [
        require('@tailwindcss/forms'),
    ],
}

This suggested that maybe node_modules or some folder with lots of .js files is being dragged in as mentioned above, and while I didn't have node_modules, I did vendor another library that had a handful of very large .js files. Not sure why this was not a problem before, but I've solved it with more strict globs as mentioned here: #8477.

@lcorniglione
Copy link

This will sound really strange, but I managed to fix the error by removing the css:

transform: translateY(-260px);

After that, everything worked.
I'm using 3.1.8 version.

@discoverlance-com
Copy link

discoverlance-com commented Oct 4, 2022

I found that I was experiencing this error when accessing the theme directly for the font family.

// my tailwind plugin config 
...
extend: {
  fontFamily: ({ theme }) => ({
    sans: ['Roboto', ...theme('fontFamily.sans')],
  }),
},
...

I am guessing that one cannot access fontFamily from the theme object or I was accessing it in the wrong way.
In the end I had to use const defaultTheme = require('tailwindcss/defaultTheme') to get the theme.

@danielcavanagh
Copy link

danielcavanagh commented Feb 17, 2023

i got this when i used bg-[url(...] but left off the final ). it just recurses infinitely, looking for that elusive ) it'll never find :(

@GabrielSuttner
Copy link

GabrielSuttner commented Jul 6, 2023

I am having this same issue when I use
<tailwind.config.js>
theme: { ... colors: ({ theme }) => ({ primary: 'rgb(var(--color-primary) )', action: 'rgb(var(--color-action) )', ...theme('colors') }),

if I remove
...theme('colors')
so that the colors portion of my file is just
colors: ({ theme }) => ({ primary: 'rgb(var(--color-primary) )', action: 'rgb(var(--color-action) )' }),
then it works just fine.

I am using "tailwindcss": "^3.3.2",

@arkmech
Copy link

arkmech commented Oct 29, 2023

I get the same error. But it makes sense I guess. I am using the theme function on top level properties. The theme function is then called on dozens and dozens of properties.

Seems like the theme function can only be used sparingly? Like someone mentioned above, recursive. My colors property is referencing colors.

My workaround that I will try tomorrow is any value that needs to be referenced, just make a separate object and reference it from there

note: I’m not referencing default tailwind values, but my own values

@cuiyajie
Copy link

I got same error. Because I import tailwindcss preprocessor in a lib package, Then I also import tailwindcss preprocess in main project, then the error happend.

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 a pull request may close this issue.