首页 > 解决方案 > 请帮我理解为什么创建vue项目时会出错

问题描述

请帮我弄清楚?创建vue项目时出错。

我正在展示我在创建 vue 项目时选择的内容。我不明白为什么会出现错误。我正在展示配置VS CODE。

我正在展示我在创建 vue 项目时选择的内容。我不明白为什么会出现错误。我正在展示配置VS CODE。

$ vue 创建 myapp

Vue CLI v4.5.13
? Please pick a preset: Manually select features
? Check the features needed for your project: (Press <space> to select, <a> to? Check the features needed for your project: Choose Vue version, Babel, CSS P
re-processors, Linter
? Choose a version of Vue.js that you want to start the project with (Use arro? Choose a version of Vue.js that you want to start the project with 2.x
? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supporte? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supporte? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supporte
d by default): Sass/SCSS (with node-sass)
? Pick a linter / formatter config: Airbnb
? Pick additional lint features: (Press <space> to select, <a> to toggle all,
? Pick additional lint features: Lint on save
? Where do you prefer placing config for Babel, ESLint, etc.? (Use arrow keys)? Where do you prefer placing config for Babel, ESLint, etc.? In dedicated con
fig files
? Save this as a preset for future projects? No


npm ERR! code 1
npm ERR! path C:\vue-projects\Ud\0 fifth VUE JS\myapp\node_modules\node-sass
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c node scripts/build.js
npm ERR! Building: C:\Program Files\nodejs\node.exe C:\vue-projects\Ud\0 fifth VUE JS\myapp\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp verb cli [
npm ERR! gyp verb cli   'C:\\Program Files\\nodejs\\node.exe',
npm ERR! gyp verb cli   'C:\\vue-projects\\Ud\\0 fifth VUE JS\\myapp\\node_modules\\node-gyp\\bin\\node-gyp.js',
npm ERR! gyp verb cli   'rebuild',
npm ERR! gyp verb cli   '--verbose',
npm ERR! gyp verb cli   '--libsass_ext=',
npm ERR! gyp verb cli   '--libsass_cflags=',
npm ERR! gyp verb cli   '--libsass_ldflags=',
npm ERR! gyp verb cli   '--libsass_library='
npm ERR! gyp verb cli ]
npm ERR! gyp info using node-gyp@3.8.0
npm ERR! gyp info using node@16.0.0 | win32 | x64
npm ERR! gyp verb command rebuild []
npm ERR! gyp verb command clean []
npm ERR! gyp verb clean removing "build" directory
npm ERR! gyp verb command configure []
npm ERR! gyp verb check python checking for Python executable "python2" in the PATH
npm ERR! gyp verb `which` failed Error: not found: python2
npm ERR! gyp verb `which` failed     at getNotFoundError (C:\vue-projects\Ud\0 fifth VUE JS\myapp\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (C:\vue-projects\Ud\0 fifth VUE JS\myapp\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (C:\vue-projects\Ud\0 fifth VUE JS\myapp\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at C:\vue-projects\Ud\0 fifth VUE JS\myapp\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at C:\vue-projects\Ud\0 fifth VUE JS\myapp\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed     at C:\vue-projects\Ud\0 fifth VUE JS\myapp\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:194:21)
npm ERR! gyp verb `which` failed  python2 Error: not found: python2
npm ERR! gyp verb `which` failed     at getNotFoundError (C:\vue-projects\Ud\0 fifth VUE JS\myapp\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (C:\vue-projects\Ud\0 fifth VUE JS\myapp\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (C:\vue-projects\Ud\0 fifth VUE JS\myapp\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at C:\vue-projects\Ud\0 fifth VUE JS\myapp\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at C:\vue-projects\Ud\0 fifth VUE JS\myapp\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed     at C:\vue-projects\Ud\0 fifth VUE JS\myapp\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:194:21) {
npm ERR! gyp verb `which` failed   code: 'ENOENT'
npm ERR! gyp verb `which` failed }
npm ERR! gyp verb check python checking for Python executable "python" in the
PATH
npm ERR! gyp verb `which` failed Error: not found: python
npm ERR! gyp verb `which` failed     at getNotFoundError (C:\vue-projects\Ud\0 fifth VUE JS\myapp\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (C:\vue-projects\Ud\0 fifth VUE JS\myapp\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (C:\vue-projects\Ud\0 fifth VUE JS\myapp\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at C:\vue-projects\Ud\0 fifth VUE JS\myapp\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at C:\vue-projects\Ud\0 fifth VUE JS\myapp\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed     at C:\vue-projects\Ud\0 fifth VUE JS\myapp\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:194:21)
npm ERR! gyp verb `which` failed  python Error: not found: python
npm ERR! gyp verb `which` failed     at getNotFoundError (C:\vue-projects\Ud\0 fifth VUE JS\myapp\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (C:\vue-projects\Ud\0 fifth VUE JS\myapp\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (C:\vue-projects\Ud\0 fifth VUE JS\myapp\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at C:\vue-projects\Ud\0 fifth VUE JS\myapp\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at C:\vue-projects\Ud\0 fifth VUE JS\myapp\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed     at C:\vue-projects\Ud\0 fifth VUE JS\myapp\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:194:21) {
npm ERR! gyp verb `which` failed   code: 'ENOENT'
npm ERR! gyp verb `which` failed }
npm ERR! gyp verb could not find "python". checking python launcher
npm ERR! gyp verb could not find "python". guessing location
npm ERR! gyp verb ensuring that file exists: C:\Python27\python.exe
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Can't find Python executable "python", you can
set the PYTHON env variable.
npm ERR! gyp ERR! stack     at PythonFinder.failNoPython (C:\vue-projects\Ud\0 fifth VUE JS\myapp\node_modules\node-gyp\lib\configure.js:484:19)
npm ERR! gyp ERR! stack     at PythonFinder.<anonymous> (C:\vue-projects\Ud\0 fifth VUE JS\myapp\node_modules\node-gyp\lib\configure.js:509:16)
npm ERR! gyp ERR! stack     at callback (C:\vue-projects\Ud\0 fifth 
VUE JS\myapp\node_modules\graceful-fs\polyfills.js:299:20)
npm ERR! gyp ERR! stack     at FSReqCallback.oncomplete (node:fs:194:21)
npm ERR! gyp ERR! System Windows_NT 6.3.9600
npm ERR! gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\vue-projects\\Ud\\0 fifth VUE JS\\myapp\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
npm ERR! gyp ERR! cwd C:\vue-projects\Ud\0 fifth VUE JS\myapp\node_modules\node-sass
npm ERR! gyp ERR! node -v v16.0.0
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok
npm ERR! Build failed with error code: 1

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Ulys\AppData\Local\npm-cache\_logs\2021-09-13T20_23_21_730Z-debug.log
 ERROR  command failed: npm install --loglevel error --legacy-peer-deps

这是我的 VS 代码配置:

{
    "liveSassCompile.settings.generateMap": false,
    "liveSassCompile.settings.formats": [
        {
            "format": "expanded",
            "autoprefix": "last 5 versions",
            "extensionName": ".css",
            "savePath": "css"
        }
    ],
    "javascript.suggest.names": false,
    "editor.lineHeight": 16,
    "editor.renderWhitespace": "all",
    "editor.tabSize": 2,
    "emmet.includeLanguages": {
        "javascript": "javascriptreact",
        "vue-html": "html"
    },
    "eslint.validate": [
        "javascript",
        "javascriptreact",
        "vue",
        "html",
    ],
    "emmet.triggerExpansionOnTab": true,
    "explorer.confirmDelete": false,
    "explorer.confirmDragAndDrop": false,
    "files.eol": "\n",
    "terminal.integrated.fontSize": 12,
    "workbench.startupEditor": "none",
    "[javascript]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "[javascriptreact]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "[html]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "[json]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "[jsonc]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "files.trimTrailingWhitespace": true,
    "editor.minimap.enabled": true,
    "javascript.updateImportsOnFileMove.enabled": "always",
    "diffEditor.ignoreTrimWhitespace": true,
    "window.titleBarStyle": "custom",
    "breadcrumbs.enabled": false,
    "editor.fontLigatures": true,
    "gitlens.views.repositories.location": "scm",
    "gitlens.views.fileHistory.location": "gitlens",
    "gitlens.views.lineHistory.location": "gitlens",
    "gitlens.views.compare.location": "gitlens",
    "gitlens.views.search.location": "gitlens",
    "workbench.activityBar.visible": true,
    "workbench.statusBar.visible": true,
    "workbench.editor.showTabs": true,
    "files.autoSave": "afterDelay",
    "files.autoSaveDelay": 500,
    "eslint.alwaysShowStatus": true,
    "eslint.autoFixOnSave": true,
    "npm.enableScriptExplorer": true,
    "editor.largeFileOptimizations": false,
    "editor.formatOnType": true,
    "editor.formatOnPaste": true,
    "terminal.external.windowsExec": "C:\\Program Files\\Git\\bin\\bash.exe",
    "terminal.integrated.defaultProfile.windows": "Git Bash",
    "editor.wordWrap": "on"
}

标签: javascriptnode.jsvue.jsnpmvuejs2

解决方案


该错误是在未安装 Python 的情况下安装node-sass(即选择CSS Pre-processors和)的副作用。的uses ,它需要 Python,因此如果环境路径中没有可用的二进制文件,则会失败。Sass/SCSS (with node-sass)node-sasspostinstallnode-gyppythonpostinstall

node-sass不是默认预设的一部分,因此您不会看到安装默认设置的错误。

解决方案 1

安装 Python。包安装程序通常将python二进制文件添加到环境路径中。确保重新启动任何打开的终端以获取更新的环境。

解决方案 2

使用 Vue CLI 5.x,它node-sasssass.

您可以通过以下方式升级到5.0.0-beta.3(tagged next):

npm i -g @vue/cli@next

或运行它npx

npx @vue/cli@next create my-vue-project

推荐阅读