gatsby 构建在 netlify 上失败并抛出 new ERR_REQUIRE_ESM(filename, ParentPath, packageJsonPath);

2023-12-26

几个月前我的构建中没有发生此错误,我在节点上v14.4.0正在使用npm v6.14.5.

6:09:13 PM: $ gatsby build
6:09:13 PM: internal/modules/cjs/loader.js:1085
6:09:13 PM:       throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
6:09:13 PM:       ^
6:09:13 PM: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /opt/build/repo/node_modules/dot-prop/index.js
6:09:13 PM: require() of ES modules is not supported.
6:09:13 PM: require() of /opt/build/repo/node_modules/dot-prop/index.js from /opt/build/repo/node_modules/configstore/index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
6:09:13 PM: Instead rename /opt/build/repo/node_modules/dot-prop/index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /opt/build/repo/node_modules/dot-prop/package.json.
6:09:13 PM:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1085:13)
6:09:13 PM:     at Module.load (internal/modules/cjs/loader.js:933:32)
6:09:13 PM:     at Function.Module._load (internal/modules/cjs/loader.js:774:14)
6:09:13 PM:     at Module.require (internal/modules/cjs/loader.js:957:19)
6:09:13 PM:     at require (internal/modules/cjs/helpers.js:88:18)
6:09:13 PM:     at Object.<anonymous> (/opt/build/repo/node_modules/configstore/index.js:8:17)
6:09:13 PM:     at Module._compile (internal/modules/cjs/loader.js:1068:30)
6:09:13 PM:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
6:09:13 PM:     at Module.load (internal/modules/cjs/loader.js:933:32)
6:09:13 PM:     at Function.Module._load (internal/modules/cjs/loader.js:774:14) {
6:09:13 PM:   code: 'ERR_REQUIRE_ESM'
6:09:13 PM: }

这是上次构建的日志输出 https://gist.githubusercontent.com/samgermain/3df18bf3c709406df1b3769dd705fd61/raw/ed26dd03352adbe3ace2fb593fd79e278410bd88/working%2520build

这是工作构建后构建 1 的日志输出 https://gist.githubusercontent.com/samgermain/3df18bf3c709406df1b3769dd705fd61/raw/eb53068d7bc6201f84627f3445201934478502e2/build%25201%2520after%2520working%2520build。除了新图像和一些字符串之外,没有任何更新。这次构建失败了。

上述两个版本的节点版本都设置为v14.4.0

这是我最近的 Netlify 日志 https://gist.githubusercontent.com/samgermain/3df18bf3c709406df1b3769dd705fd61/raw/20e8f2f8a68a1ee3eb897a5fec43d2b54a24427a/netlify%2520log

它发生在这是我的 package-lock.json https://gist.githubusercontent.com/samgermain/3df18bf3c709406df1b3769dd705fd61/raw/71fa254de3da31ea2addf1585b239383b689e340/breaking%2520package-lock.json

但不会发生时这是我的 package-lock.json https://gist.githubusercontent.com/samgermain/3df18bf3c709406df1b3769dd705fd61/raw/71fa254de3da31ea2addf1585b239383b689e340/working%2520package-lock.json

即使有工作package-lock.json我必须使用节点v14.17.0和 npmv7.20.5否则我会得到同样的错误


使用工作 package-lock.json 和工作节点以及 npm 版本,我收到这个新错误 https://gist.githubusercontent.com/samgermain/3df18bf3c709406df1b3769dd705fd61/raw/20e8f2f8a68a1ee3eb897a5fec43d2b54a24427a/New%2520error%2520with%2520the%2520non-breaking%2520package-lock.json

6:49:50 PM: success Running gatsby-plugin-sharp.IMAGE_PROCESSING jobs - 144.047s - 675/675 4.69/s
6:49:50 PM: error UNHANDLED EXCEPTION write EPIPE
6:49:50 PM: 
6:49:50 PM: 
6:49:50 PM:   Error: write EPIPE
6:49:50 PM:   
6:49:50 PM:   - child_process.js:839 ChildProcess.target._send
6:49:50 PM:     internal/child_process.js:839:20
6:49:50 PM:   
6:49:50 PM:   - child_process.js:710 ChildProcess.target.send
6:49:50 PM:     internal/child_process.js:710:19
6:49:50 PM:   
6:49:50 PM:   - index.js:298 WorkerPool.sendMessage
6:49:50 PM:     [repo]/[gatsby-worker]/dist/index.js:298:19
6:49:50 PM:   
6:49:50 PM:   - worker-messaging.ts:22 
6:49:50 PM:     [repo]/[gatsby]/src/utils/jobs/worker-messaging.ts:22:22

这是我的 package.json

{
  "name": "suddenly-saskatchewan-magazine-website",
  "private": true,
  "description": "Suddenly Saskachewan Magazine Website",
  "version": "0.1.0",
  "author": "Sam Germain",
  "keywords": [
    "suddenly saskatchewan",
    "saskatchewan"
  ],
  "license": "MIT",
  "scripts": {
    "build": "GATSBY_EXPERIMENTAL_PAGE_BUILD_ON_DATA_CHANGES=true gatsby build --log-pages",
    "develop": "gatsby develop",
    "format": "prettier --write \"**/*.{js,jsx,json,md}\"",
    "preinstall": "npx npm-force-resolutions",
    "start": "npm run develop",
    "serve": "gatsby serve",
    "test": "echo \"Write tests! -> https://gatsby.dev/unit-testing \"",
    "type-check": "tsc -w"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/samgermain/sudSaskV2.git"
  },
  "bugs": {
    "url": "https://github.com/samgermain/sudSaskV2/issues"
  },
  "resolutions": {
    "dot-prop": ">=5.2.0"
  },
  "dependencies": {
    "@fortawesome/fontawesome-svg-core": "^6.1.1",
    "@fortawesome/free-brands-svg-icons": "^6.1.1",
    "@fortawesome/free-solid-svg-icons": "^6.1.1",
    "@fortawesome/react-fontawesome": "^0.1.18",
    "@loadable/component": "^5.15.2",
    "@pittica/gatsby-plugin-recaptcha": "^2.0.3",
    "@types/react-helmet": "^6.1.5",
    "@types/react-scroll": "^1.8.3",
    "bootstrap": "^5.1.3",
    "core-js": "^3.21.1",
    "emailjs-com": "^3.2.0",
    "gatsby": "^4.11.3",
    "gatsby-background-image": "^1.6.0",
    "gatsby-image": "^3.11.0",
    "gatsby-plugin-create-client-paths": "^4.9.0",
    "gatsby-plugin-google-analytics": "^4.11.0",
    "gatsby-plugin-google-fonts": "^1.0.1",
    "gatsby-plugin-graphql-loader": "^1.0.2",
    "gatsby-plugin-loadable-components-ssr": "^4.2.0",
    "gatsby-plugin-manifest": "^4.11.1",
    "gatsby-plugin-netlify": "^4.2.0",
    "gatsby-plugin-preact": "^6.11.0",
    "gatsby-plugin-preconnect": "^1.3.0",
    "gatsby-plugin-purgecss": "^6.1.2",
    "gatsby-plugin-react-helmet": "^5.11.0",
    "gatsby-plugin-react-svg": "^3.1.0",
    "gatsby-plugin-root-import": "^2.0.8",
    "gatsby-plugin-sass": "^5.11.1",
    "gatsby-plugin-sharp": "^4.11.1",
    "gatsby-plugin-sitemap": "^5.11.1",
    "gatsby-plugin-typescript": "^4.11.1",
    "gatsby-remark-images": "^6.11.1",
    "gatsby-remark-relative-images-v2": "^0.1.5",
    "gatsby-source-filesystem": "^4.11.1",
    "gatsby-transformer-remark": "^5.11.1",
    "gatsby-transformer-sharp": "^4.11.0",
    "graphql-tag": "^2.12.6",
    "jshint": "^2.13.4",
    "node-sass": "^6.0.1",
    "preact": "^10.7.1",
    "preact-render-to-string": "^5.1.21",
    "prop-types": "^15.8.1",
    "query-string": "^7.1.1",
    "react": "^17.0.2",
    "react-bootstrap": "^2.2.3",
    "react-dom": "^17.0.2",
    "react-helmet": "^6.1.0",
    "react-scroll": "^1.8.7",
    "resize-observer-polyfill": "^1.5.1",
    "typescript": "^4.6.3",
    "webpack": "^5.72.0"
  }
}

这是我上次构建的 package.json https://gist.githubusercontent.com/samgermain/3df18bf3c709406df1b3769dd705fd61/raw/f1a65fe3948aae151970d792e1670f6ac5b871cb/package.json%2520for%2520the%2520last%2520working%2520build


在 gatsby 云上构建时,我遇到了相同的构建错误


我的网站仍在使用gatsby-image代替gatsby-plugin-image,我有一个分支,我花了几个小时尝试切换gatsby-image to gatsby-plugin-image,但是还是有问题,不知道这次更新能不能解决这个问题


UPDATE

Netlify 上的一个随机构建工作正常


错误未处理异常写入 EPIPE

此错误通常与服务器的超时响应有关,并且根据某些构建参数,它可能会失败或不失败,这就是它以前没有发生的原因。

出现超时的原因有多种(新包、缓存文件丢失、硬图像处理等)。就你而言,我认为这与图像处理过程有关。尝试删除AVIF(这是 CPU 密集型的)如果您正在使用它并使用默认格式(WEBP and auto).

在这种情况下gatsby-plugin-image分支尝试设置默认选项:

module.exports = {
  plugins: [
    {
      resolve: `gatsby-plugin-sharp`,
      options: {
        defaults: {
          formats: [`auto`, `webp`],
          placeholder: `dominantColor`,
          quality: 50,
          breakpoints: [750, 1080, 1366, 1920],
          backgroundColor: `transparent`,
          tracedSVGOptions: {},
          blurredOptions: {},
          jpgOptions: {},
          pngOptions: {},
          webpOptions: {},
          avifOptions: {},
        }
      }
    },
    `gatsby-transformer-sharp`,
    `gatsby-plugin-image`,
  ],
}

如果是gatsby-image,尝试使用特定查询片段withWebp https://www.gatsbyjs.com/docs/reference/built-in-components/gatsby-image/#image-query-fragments.

在 Netlify 方面绕过这种 CPU 密集型工作的另一种方法是使用 Netlify 提供的 CDN 与 Gatsby 图像一起使用,这将在构建过程中节省大量耗时的过程。更多详情请参见:

  • https://www.netlify.com/blog/gatsby-image-cdn-on-netlify https://www.netlify.com/blog/gatsby-image-cdn-on-netlify
  • https://github.com/netlify/netlify-plugin-gatsby/blob/main/docs/image-cdn.md https://github.com/netlify/netlify-plugin-gatsby/blob/main/docs/image-cdn.md

如果问题仍然存在,另一个已知的可行解决方案是将 Gatsby 从^4.11.3 to 4.7.2,如果需要锁定版本。

有关所描述解决方案的更详细说明可以在以下位置找到:

  • https://answers.netlify.com/t/error-unhandled-exception-write-epipe/52650 https://answers.netlify.com/t/error-unhandled-exception-write-epipe/52650
  • https://github.com/netlify/netlify-plugin-gatsby/issues/259 https://github.com/netlify/netlify-plugin-gatsby/issues/259

根据dot-drop错误,原因是在你的node_modules或者在您的代码中,您的依赖项同时使用type=module和并且没有type=module (https://github.com/standard-things/esm/issues/868#issuecomment-586705453 https://github.com/standard-things/esm/issues/868#issuecomment-586705453)。这通常是由依赖项升级或 Node 版本更改引起的。

尝试在以下位置设置捆绑器netlify.toml file:

[functions]
  node_bundler = "esbuild"

Source: https://answers.netlify.com/t/getting-must-use-import-to-load-es-module-when-using-node-fetch-in-netlify-functions/47230 https://answers.netlify.com/t/getting-must-use-import-to-load-es-module-when-using-node-fetch-in-netlify-functions/47230

或者,将以下行添加到您的package.json:

{
  "type": "module"
}

这本质上启用了 ES6 模块。

更多详情请参见:为什么 package.json 文件中包含“type: module”? https://stackoverflow.com/questions/61401475/why-is-type-module-in-package-json-file

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

gatsby 构建在 netlify 上失败并抛出 new ERR_REQUIRE_ESM(filename, ParentPath, packageJsonPath); 的相关文章

  • Meteor.setTimeout 和 Meteor.methods 之间的并发

    在我的 Meteor 应用程序中实现回合制多人游戏服务器 客户端通过发布 订阅接收游戏状态 并且可以调用 Meteor 方法sendTurn将回合数据发送到服务器 他们无法直接更新游戏状态集合 var endRound function g
  • 监听文件夹和文件(更改)

    可以直接在 PHP 或 Node 上监听文件夹和文件的更改 通过事件 还是我需要创建自己的方法来执行此操作 Example 我需要听文件夹 user 如果我将一些文件添加到该目录中 PHP 或 Node 会收到信息并运行PathEvent
  • 尝试安装 LESS 时出现“请尝试以 root/管理员身份再次运行此命令”错误

    我正在尝试在我的计算机上安装 LESS 并且已经安装了节点 但是 当我输入 node install g less 时 出现以下错误 并且不知道该怎么办 FPaulMAC bin paul npm install g less npm ER
  • 为什么 Node.js 应用程序只能从 127.0.0.1/localhost 访问?

    我本来打算教我的朋友介绍 Node 但是后来 我想知道为什么这个代码来自nodejs org var http require http http createServer function req res res writeHead 20
  • 如何使用 sinon/mocha 模拟 npm 模块

    我正在尝试测试调用该模块的函数cors 我想测试一下cors会被称为 为此 我必须存根 模拟它 这是函数 cors js const cors require cors const setCors gt cors origin http l
  • npmjs.org - 找不到自述文件

    我是 npm 包的主要作者scramjet 一个月以来 我遇到了关于可视性的问题README md在 npmjs 中 The npm 中的超燃冲压发动机包 https www npmjs com package scramjet shows
  • 在 Node 中使用 Babel 导入与请求 [重复]

    这个问题在这里已经有答案了 我想在一个文件中导入一个类 use strict import models from model class Foo bar export default new Foo 当我使用导入时它有效 例如 impor
  • 如何解决 Socket.io 404(未找到)错误?

    我正在使用 Socket io 和 Express 在我的项目中 我有一个登录页面和一个主页 当我成功登录时 我导航到 localhost 3000 home 并收到以下错误 GET http localhost 3000 socket i
  • libxmljs 的替代品 [关闭]

    Closed 此问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 目标 使用 Node js 访问网页 使用 xpath 语法操作 DOM 并打印新的 DOM libxm
  • 节点无法抓取某些页面

    我不知道这是否与冷融合页面有关 但我无法刮掉这些 cfm pages 在目录中的命令行中request run node gt var request require request node gt var url http linguis
  • editMessageReplyMarkup 方法删除内联键盘

    我正在使用 node js 制作一个电报机器人node telegram bot api图书馆 我回答callback query并想更换我的内联键盘 下面的代码显示了我如何尝试使用此方法 但是当我在电报中点击键盘时 它就消失了 bot o
  • 找不到“节点”的类型定义文件

    更新 Angular Webpack 和 TypeScript 后出现奇怪的错误 知道我可能会错过什么吗 当我使用 npm start 运行应用程序时 出现以下错误 at loader Cannot find type definition
  • 下载中带有文件名的 NodeJS sendFile

    我尝试使用以下代码将文件发送给客户端 router get get myfile function req res next res sendFile other file name dat 它工作正常 但当用户从以下网址下载此文件时我需要
  • github actions 找不到 package.json

    我正在尝试设置一些基本的 GitHub 操作来在 PR 上撰写评论 Action 发布在 github 上 如下所示 action yml 文件 name name description description author me inp
  • 使用 Sequelize 实现单表继承

    有没有办法使用sequelize来创建单表继承 我希望有一个用于购买和 PartialPurchase 模型的 STI 其中我将有一个类型字段 该字段为 Purchase 或 PartialPurchase 以及类 Purchasing 和
  • Node js 使用中间件重定向进行过多重定向

    在我的 Node js 应用程序 我使用的是express 4 x 中 我想检查用户是否已登录 如果用户未登录 我想重定向到我的登录页面 然后我在中间件中这样做 服务器 js app use function req res next if
  • 具有 Firebase (FCM) 推送通知的 Node js

    我正在使用 Node js 开发 REST api 并且有一个休息端点来发送 firebase 推送通知 我的代码如下 const bodyParser require body parser var cors require cors v
  • Mongoose 和 Promise:如何获取查询结果数组?

    使用猫鼬从数据库和 Q 中查询结果以获取承诺 但发现很难只获取可用用户列表 目前我有一些这样的东西 var checkForPerson function person people mongoose model Person Person
  • 流星内存不足

    我正在使用流星来制作报废引擎 我必须执行一个 HTTP GET 请求 这会向我发送一个 xml 但这个 xml 大于 400 ko 我得到一个异常 内存不足 result Meteor http get http SomeUrl com 致
  • 如何使用 Passport 验证 Supertest 请求?

    我使用 Passport js 进行身份验证 本地策略 并使用 Mocha 和 Supertest 进行测试 如何使用 Supertest 创建会话并发出经过身份验证的请求 正如 zeMirco 指出的那样 底层superagent模块支持

随机推荐