Tag Archives: node-sass

How to Solve Stack error: eacces: permission denied, MKDIR

Recently, I encountered a node sass package installation problem in my own project. The problem is as follows. When I sudo NPMI get the following error message, I tried to modify the permissions and the version of the package, but I still couldn’t solve it. Finally, Google finally solved it. Here, I write down the cause of the problem and the solution

gyp verb build dir attempting to create "build" dir: /Study/github/react-view/node_modules/node-sass/build
gyp ERR! configure error 
gyp ERR! stack Error: EACCES: permission denied, mkdir '/Study/github/react-view/node_modules/node-sass/build'
gyp ERR! System Darwin 17.7.0
gyp ERR! command "/usr/local/bin/node" "/Study/github/react-view/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /Study/github/react-view/node_modules/node-sass
gyp ERR! node -v v10.15.3
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 

First of all, the reason for this problem is that NPM will have a life cycle, and a package will have a life cycle to execute something. For security reasons, it will be automatically degraded, resulting in no permission to perform some operations. Use the — unsafe perm parameter to unlock the restriction. Before the NPM lifecycle command is executed, it will judge that the configuration of unsafe perm is true before continuing, otherwise it will exit ahead of time

 // lib/utils/lifecycle.js
    unsafe = unsafe || npm.config.get('unsafe-perm')
    if ((wd.indexOf(npm.dir) !== 0 || _incorrectWorkingDirectory(wd, pkg)) && !unsafe && pkg.scripts[stage]) {
      log.warn('lifecycle', logid(pkg, stage), 'cannot run in wd',
        '%s %s (wd=%s)', pkg._id, pkg.scripts[stage], wd
      )
      return cb()
    }

For the reading order of configuration, please refer to NPM config, that is, CLI – > env -> npmrc -> default。

The initialization of unsafe perm in default is as follows:

// lib/config/defaults.js
    'unsafe-perm': process.platform === 'win32' ||
                     process.platform === 'cygwin' ||
                     !(process.getuid && process.setuid &&
                       process.getgid && process.setgid) ||
                     process.getuid() !== 0

For UNIX platform, the default value of NPM command executed by root user will be false

solutions :

Temporarily modify NPM configuration during installation sudo NPM install — unsafe perm

Set the default configuration of NPM in the project NPM config set unsafe perm = true

Create. Npmrc in the project to override the default configuration

// .npmrc
unsafe-perm = true

Global setting NPM config – G set unsafe perm

Here, you need to change the permission of the node directory to root

chown root:root node

Solutions provided by NPM

 ## create .npm-global folder
 mkdir ~/.npm-global
 ## set
 npm config set prefix '~/.npm-global'
 export PATH=~/.npm-global/bin:$PATH
 source ~/.profile

 

Module build failed: TypeError: this.getResolve is not a function at Object.loader node-sass Install Error

 

Error in installing node SCSS

When building Vue scaffold or in Vue project, you want to use sass function,

npm install node-sass --save-dev 		
npm install sass-loader --save-dev 		
npm install style-loader --save-dev 		

After the installation is complete, an error occurred at runtime

Modele build failed: TypeError: this.getResolve is not a function at Object.loader...

This is because the current version of SASS is too high, and there is an error during the compilation of webpack. At this time, you only need to change to a lower version. Next, I’ll talk about the modification method. It’s very simple, as follows: find the package.json Just replace the version of “sass loader” in the file.

My local is replacing "sass-loader":"^8.0.0", with "sass-loader":"^7.3.1",

At this time to run the project again, it runs successfully.

You can also uninstall the current version first and then install the specified version

Uninstall the current version npm uninstall sass-loader
Install     npm install [email protected] --save-dev