简体   繁体   中英

Project missing node_modules dir but npm intall fails

My project is missing it's node_modules dir. I've tried running npm install, but it fails like this:

...
npm WARN deprecated core-js@2.6.11: core-js@<3.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
npm ERR! code 1
npm ERR! path C:\users\me\IdeaProjects\portal\cp-frontend\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:\users\me\IdeaProjects\portal\cp-frontend\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
npm ERR! Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
npm ERR! Build started 10/1/2021 3:15:35 PM.
npm ERR! Project "C:\users\me\IdeaProjects\portal\cp-frontend\node_modules\node-sass\build\binding.sln" on node 1 (default targets).
npm ERR! ValidateSolutionConfiguration:
npm ERR!   Building solution configuration "Release|x64".
npm ERR! Project "C:\users\me\IdeaProjects\portal\cp-frontend\node_modules\node-sass\build\binding.sln" (1) is building "C:\users\me\IdeaProjects\portal\cp-frontend\node_modules\node-sass\build\binding.vcxproj.metaproj" (2) on node 1 (default targets).
...

I've tried

npm install --global --production windows-build-tools@4.0.0

in powershell as administrator, then exit and re-enter powershell as administrator, then trying npm install but still get this error.

Any ideas? I've tried googling it, and the suggestion was npm install --global --production windows-build-tools@4.0.0 (without @4.0.0 that fails too).

Looking at the packages.json file, it lists these dependencies. I'm not sure if that is helpful or not.

{
  "name": "customer-portal-frontend",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "antd": "^4.1.0",
    "autoprefixer": "^9.7.6",
    "axios": "^0.19.2",
    "classnames": "^2.2.6",
    "crypto-js": "^4.0.0",
    "dayjs": "^1.8.23",
    "node-sass": "^4.13.1",
    "normalize.css": "^8.0.1",
    "numeral": "^2.0.6",
    "query-string": "^6.12.1",
    "react": "^16.12.0",
    "react-app-polyfill": "^1.0.6",
    "react-dom": "^16.12.0",
    "react-ga": "^2.7.0",
    "react-helmet": "^6.1.0",
    "react-hook-form": "^5.3.1",
    "react-intercom": "^1.0.15",
    "react-responsive-tabs": "^3.3.0",
    "react-router-dom": "^5.1.2",
    "react-scripts": "^3.4.1",
    "reactn": "^2.2.6",
    "tailwindcss": "^1.2.0",
    "victory": "^34.1.3"
  },
  "scripts": {
    "start": "npm run tailwind:css && react-scripts start",
    "build": "npm run tailwind:css && react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "tailwind:css": "tailwind build src/tailwind.src.css -c tailwind.js -o src/tailwind.css"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      "ie 11",
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ],
    "development": [
      "ie 11",
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

If I use npm start in the next level up dir, I get a popup regarding (but it's probably too early to do npm start since there's no node_modules dir and npm install fails)

Script: c:\Users\me\IdeaProjects\portal\cp-frontend\tailwind.js
Line: 32
Char: 7
Error: expected identifier, string or number
Code: 800A0404
Source: Microsoft JScript compilation error

Update 1:

Ran npm install node-gyp in the frontend dir and see similar errors as npm install.  I can run that fine in the backend dir. I don't know why this dir fails.  I have windows command prompt open as administrator in both cases..not sure if that would matter.

npm ERR! code 1
npm ERR! path C:\Users\me\IdeaProjects\portal\cp-frontend\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:\Users\me\IdeaProjects\portal\cp-frontend\node_modules\node-sass\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
npm ERR! Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
npm ERR! Build started 10/4/2021 8:35:00 AM.
npm ERR! Project "C:\Users\me\IdeaProjects\portal\cp-frontend\node_modules\node-sass\build\binding.sln" on node 1 (default targets).
npm ERR! ValidateSolutionConfiguration:
npm ERR!   Building solution configuration "Release|x64".
npm ERR! Project "C:\Users\me\IdeaProjects\portal\cp-frontend\node_modules\node-sass\build\binding.sln" (1) is building "C:\Users\me\IdeaProjects\portal\cp-frontend\node_modules\node-sass\build\binding.vcxproj.metaproj" (2) on node 1 (default targets).
npm ERR! Project "C:\Users\me\IdeaProjects\portal\cp-frontend\node_modules\node-sass\build\binding.vcxproj.metaproj" (2) is building "C:\Users\me\IdeaProjects\portal\cp-frontend\node_modules\node-sass\build\src\libsass.vcxproj" (3) on node 1 (default targets).
npm ERR! C:\Users\me\IdeaProjects\portal\cp-frontend\node_modules\node-sass\build\src\libsass.vcxproj(20,3): error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

...

Update2: Tried npm cache clean --force. Then npm install sass, but it's still trying to do npm install node-sass.

npm ERR! code 1
npm ERR! path C:\Users\me\IdeaProjects\portal\cp-frontend\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:\Users\me\IdeaProjects\portal\cp-frontend\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
npm ERR! Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.

Delete current folder node_modules and run npm as a regular user, non administrator/root.

Try ever possible avoid run npm commands as Administrator/Root, this is a pratice discouraged, because third's commands may be executed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM