【问题标题】:GatsbyJS blog not compiling anymore after "npm update"?GatsbyJS 博客在“npm update”之后不再编译?
【发布时间】:2019-01-18 10:42:22
【问题描述】:

如果是 Gatsby、webpack 或 npm 问题,我还不明白。

我在终端中执行了这些命令,他们似乎已经开始了这个问题,试图修复一个有“找不到模块”错误的 material-ui“Popper”模块。

npm install react-popper@next --save    
npm install avj    
npm install --save-dev webpack    
npm install & npm update

终端:

错误加载本地开发命令时出现问题。盖茨比 可能没有安装。也许您需要运行“npm install”?

错误:找不到模块“webpack/lib/removeAndDo”

package.json

{
  "name": "auto-club-reviews",
  "description": "Auto Club Reviews Blog",
  "version": "1.0.0",
  "author": "Sofianu Alin",
  "dependencies": {
    "@material-ui/core": "^1.4.3",
    "@material-ui/icons": "^1.1.0",
    "gatsby": "^1.9.277",
    "gatsby-link": "^1.6.46",
    "gatsby-plugin-feed": "^1.3.25",
    "gatsby-plugin-google-analytics": "^1.0.31",
    "gatsby-plugin-offline": "^1.0.18",
    "gatsby-plugin-react-helmet": "^2.0.11",
    "gatsby-plugin-react-next": "^1.0.11",
    "gatsby-plugin-sharp": "^1.6.48",
    "gatsby-plugin-typography": "^1.7.19",
    "gatsby-remark-copy-linked-files": "^1.5.37",
    "gatsby-remark-images": "^1.5.67",
    "gatsby-remark-responsive-iframe": "^1.4.20",
    "gatsby-remark-smartypants": "^1.4.12",
    "gatsby-source-contentful": "^1.3.54",
    "gatsby-source-filesystem": "^1.5.39",
    "gatsby-transformer-remark": "^1.7.44",
    "gatsby-transformer-sharp": "^1.6.27",
    "lodash": "^4.17.10",
    "react": "^16.4.2",
    "react-dom": "^16.4.2",
    "react-helmet": "^5.2.0",
    "react-hover": "^1.3.2",
    "react-popper": "^1.0.2",
    "typeface-roboto": "0.0.54"
  },
  "devDependencies": {
    "eslint": "^5.3.0",
    "eslint-plugin-react": "^7.10.0",
    "gh-pages": "^1.2.0",
    "html-webpack-plugin": "^3.2.0",
    "prettier": "^1.14.2",
    "webpack": "^4.16.5",
    "webpack-command": "^0.4.1",
    "webpack-dev-middleware": "^3.1.3",
    "webpack-dev-server": "^3.1.5"
  },
  "homepage": "https://github.com/gatsbyjs/gatsby-starter-blog#readme",
  "keywords": [
    "gatsby"
  ],
  "license": "MIT",
  "main": "n/a",
  "repository": {
    "type": "git",
    "url": "git+https://github.com/gatsbyjs/gatsby-starter-blog.git"
  },
  "scripts": {
    "dev": "gatsby develop",
    "lint": "./node_modules/.bin/eslint --ext .js,.jsx --ignore-pattern public .",
    "test": "echo \"Error: no test specified\" && exit 1",
    "format": "prettier --trailing-comma es5 --no-semi --single-quote --write 'src/**/*.js' 'src/**/*.md'",
    "develop": "gatsby develop",
    "build": "gatsby build",
    "deploy": "gatsby build --prefix-paths && gh-pages -d public",
    "fix-semi": "eslint --quiet --ignore-pattern node_modules --ignore-pattern public --parser babel-eslint --no-eslintrc --rule '{\"semi\": [2, \"never\"], \"no-extra-semi\": [2]}' --fix gatsby-node.js"
  }
}

也尝试过:

删除 node_modules 然后 npm 安装;

卸载 "webpack-cli": "^3.1.0" 并安装 webpack-commander;

卸载似乎在终端被抱怨的extract-text-webpack-plugin;

同志们有什么想法吗?

【问题讨论】:

    标签: node.js npm webpack gatsby


    【解决方案1】:

    您是否尝试过 Gatsby v2?您的 package.json 显示 React v16,它是 Gatsby v2 的 peerDependency,但不是 Gatsby v1。在 Gatsby v1(你在 package.json 中拥有的)中,你不应该直接安装 React,它是作为 Gatsby 的依赖项安装的。

    Webpack 也是(v1 和 v2)Gatsby 的依赖项。我认为您不应该将它作为顶级依赖项放在 package.json 中。

    我建议从一个干净的 Gatsby 启动器开始,然后将您的 gatsby-node.jsgatsby-config.js、组件、内容等复制到该项目中。保留package.json 文件。然后为您明确importrequire 的每个包运行npm install --save。希望这能让您回到正常工作的网站。

    旁注,就个人而言,我还推荐yarn 而不是npm

    【讨论】:

    • 谢谢!如果不是那么懒惰地安装这样的 91 个模块,我很确定这会奏效:) 或者也许有一个聪明的方法来做到这一点。一位朋友建议将 package.json 和 package.lock.json 替换为之前的一些版本,删除 node_modules 并运行 npm install,就成功了。
    【解决方案2】:

    盖茨比清理缓存

    然后删除节点模块

    然后

    纱线启动/npm 安装

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 2020-07-30
    • 2020-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-24
    • 2018-04-15
    • 1970-01-01
    相关资源
    最近更新 更多