为Vue JS项目安装node-sass时出错

在VueJS项目上运行“ npm install”时,遇到以下错误:

error: no matching constructor for initialization of 'v8::String::Utf8Value'
  v8::String::Utf8Value string(value);
                        ^      ~~~~~
/Users/webdevwolf/.node-gyp/12.14.1/include/node/v8.h:3046:5: note: candidate constructor not viable: no known conversion from 'v8::Local<v8::Value>' to
      'const v8::String::Utf8Value' for 1st argument
    Utf8Value(const Utf8Value&) = delete;
    ^
/Users/webdevwolf/.node-gyp/12.14.1/include/node/v8.h:3039:5: note: candidate constructor not viable: requires 2 arguments,but 1 was provided
    Utf8Value(Isolate* isolate,Local<v8::Value> obj);
    ^
1 error generated.
make: *** [Release/obj.target/binding/src/create_string.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/node-sass/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:223:5)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Darwin 19.2.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/node-sass/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /usr/local/lib/node_modules/node-sass
gyp ERR! node -v v12.14.1
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
Build failed with error code: 1
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@4.11.0 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the node-sass@4.11.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

为了解决这个问题,我尝试了以下方法:

  • 将Node更新到最新的稳定版本
  • 更新sass
  • 运行Sass 4.11.0版本的安装

我现在对此感到非常沮丧,我什至不确定这个错误的含义-有人对如何解决这个问题有任何想法吗?

norika1117 回答:为Vue JS项目安装node-sass时出错

我用-解决了这个问题 npm install node-sass

如果失败,则

  1. 删除您的node_modules文件夹
  2. npm install
  3. npm install node-sass

有时,当我使用最新版本的sass后回到旧的vue项目时,会出现此错误。清理模块并为我的项目重新安装正确的版本似乎总是可以解决它。

,

我在使用 Node 版本 16Vue 3 时遇到了类似的问题。 该问题似乎与 node-sass 相关,并且与 node 版本 16 或其他版本不兼容。其他人提到使用 Node 14 没有问题。

即使我运行 vue create app 并点击手动配置选项并选择设置/配置 node-sass,也会发生此错误。它会开始下载,但在下载 node-saas 时会冻结并退出并出现错误。

我的解决方案是下载没有 node-sass 选项的 Vue 3,然后在安装完成后,npm i -D sass sass-loader@7 而不是 npm i -D node-sass

您还需要将其添加到根目录下的 vue.config.js 文件中。

// vue.config.js
module.exports = {
  css: {
    loaderOptions: {
      sass: {
        implementation: require('sass'),},}
}

这就是运行 scss 所需的全部内容。 只是不要忘记在脚本标签中添加 lang="scss" 属性。

<style lang="scss">
.....
</style>

我从这篇文章中找到了我的解决方案: https://www.priestch.com/replace-node-sass-with-dart-sass-in-vue-cli3-based-project/

本文链接:https://www.f2er.com/2757143.html

大家都在问