sass / node-sass

:rainbow: Node.js bindings to libsass
https://npmjs.org/package/node-sass
MIT License
8.51k stars 1.32k forks source link

../node_modules/nan/nan.h, line 904 Assertion failed: (size <= imp::kMaxLength && "too large buffer") #2830

Open alaaalii opened 4 years ago

alaaalii commented 4 years ago

Description:

I'm not sure where to log this issue (I've logged it before for reference: https://github.com/nodejs/nan/issues/883).

Trying to compile a simple SASS project (that uses this: https://github.com/carbon-design-system/ibm-security) fails (after maybe 10 minutes) with this error:

Assertion failed: (size <= imp::kMaxLength && "too large buffer"), function CopyBuffer, file ../node_modules/nan/nan.h, line 904.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-ibm-security-react-app@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-ibm-security-react-app@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/alaa/.npm/_logs/2020-01-23T16_28_20_322Z-debug.log

Contents of /Users/alaa/.npm/_logs/2020-01-23T16_28_20_322Z-debug.log are:

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   '/usr/local/Cellar/node/13.6.0/bin/node',
1 verbose cli   '/usr/local/bin/npm',
1 verbose cli   'run',
1 verbose cli   'start'
1 verbose cli ]
2 info using npm@6.13.4
3 info using node@v13.6.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle my-ibm-security-react-app@0.1.0~prestart: my-ibm-security-react-app@0.1.0
6 info lifecycle my-ibm-security-react-app@0.1.0~start: my-ibm-security-react-app@0.1.0
7 verbose lifecycle my-ibm-security-react-app@0.1.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle my-ibm-security-react-app@0.1.0~start: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/alaa/Test/my-ibm-security-react-app/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Wireshark.app/Contents/MacOS
9 verbose lifecycle my-ibm-security-react-app@0.1.0~start: CWD: /Users/alaa/Test/my-ibm-security-react-app
10 silly lifecycle my-ibm-security-react-app@0.1.0~start: Args: [ '-c', 'react-scripts start' ]
11 silly lifecycle my-ibm-security-react-app@0.1.0~start: Returned: code: 1  signal: null
12 info lifecycle my-ibm-security-react-app@0.1.0~start: Failed to exec start script
13 verbose stack Error: my-ibm-security-react-app@0.1.0 start: `react-scripts start`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:321:20)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:321:20)
13 verbose stack     at maybeClose (internal/child_process.js:1028:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
14 verbose pkgid my-ibm-security-react-app@0.1.0
15 verbose cwd /Users/alaa/Test/my-ibm-security-react-app
16 verbose Darwin 19.2.0
17 verbose argv "/usr/local/Cellar/node/13.6.0/bin/node" "/usr/local/bin/npm" "run" "start"
18 verbose node v13.6.0
19 verbose npm  v6.13.4
20 error code ELIFECYCLE
21 error errno 1
22 error my-ibm-security-react-app@0.1.0 start: `react-scripts start`
22 error Exit status 1
23 error Failed at the my-ibm-security-react-app@0.1.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

I can consistently reproduce this on my machine by doing the following:

# create a standard react app
npx create-react-app my-ibm-security-react-app
cd my-ibm-security-react-app

# add node-sass and @carbon/ibm-security
yarn add node-sass @carbon/ibm-security @carbon/type

# create a .env file to add your node_modules to the SASS loader
# as described here: https://create-react-app.dev/docs/adding-a-sass-stylesheet/
# without this, imports won't work.
echo "SASS_PATH=node_modules" > .env

# rename the .css files to .scss
mv src/index.css src/index.scss
mv src/App.css src/App.scss

# edit the .js files to import .scss instead of .css
sed -i '' 's/index.css/index.scss/' src/index.js
sed -i '' 's/App.css/App.scss/' src/App.js

# add the @carbon/ibm-security scss styles to index.scss
echo '@import "@carbon/ibm-security/scss/index";' >> src/index.scss

# then start
npm run start

If I don't import the SCSS components of the ibm-security package @carbon/ibm-security/scss/index and instead just import their CSS components like this: @carbon/ibm-security/css/index.min.css the compile works fine, so I'm assuming that this is related to some buffer/memory size related to how the scss is being compiled?

xzyfer commented 4 years ago

How large are the sass files question?

alaaalii commented 4 years ago

node_modules/@carbon/ibm-security/ is 21 MB, but it has a few dependencies in the same @carbon directory, @carbon is 57 MB. Here's the breakdown of all other carbon related dependencies:

$ du -h -d1 node_modules | grep carbon
 10M    node_modules/carbon-components
 42M    node_modules/carbon-components-react
 57M    node_modules/@carbon
1.5M    node_modules/carbon-icons

Those are the sizes of the whole folders (which include .js files). But if you just wanted to know how big the total size of just .scss files in all of the above folders, then it's 5.6 MB:

$ find node_modules/*carbon* -name "*.scss" | xargs du -h -c | tail -1
5.6M    total