gatsby在netlify上生成失败,并抛出新的ERR_REQUIRE_ESM(filename,parentPath



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

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: }

这是上一次运行的构建的日志输出

以下是工作构建之后的构建1的日志输出。除了一个新的图像和一些字符串之外,什么都没有更新。此生成失败。

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

这是我最近打破Netlify日志

当这是我的package-lock.json 时就会发生这种情况

但当这是我的package-lock.json 时不会发生

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


使用工作包-lock.json和工作节点以及npm版本,我收到了这个新的错误

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

这是我的包.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"
}
}

这是我上一次构建的包.json


我在盖茨比云上构建时遇到了相同的构建错误


我的网站仍然使用gatsby-image而不是gatsby-plugin-image,我有一个分支,我花了几个小时试图将gatsby-image切换到gatsby-plugin-image,但它仍然有问题,所以我不知道这次更新是否会解决这个问题


更新

一个在netlify上随机构建的

error UNHANDLED EXCEPTION write EPIPE

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

超时可能有多种原因(新软件包、缓存文件丢失、硬图像处理等(。就你的情况而言,我认为这与图像处理过程有关。如果正在使用AVIF,请尝试删除它(它占用CPU(,并使用默认格式(WEBPauto(。

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

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

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

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

有关所述解决方案的更详细说明,请访问:

  • https://answers.netlify.com/t/error-unhandled-exception-write-epipe/52650
  • 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(。这通常是由依赖项的升级或Node版本的更改引起的。

尝试在netlify.toml文件中设置打包程序:

[functions]
node_bundler = "esbuild"

来源: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模块。

更多详细信息,请访问:Why is';类型:模块';在package.json文件中?

您的write EPIPE错误是Netlify中gatsby v4构建发生的超时,解决方法是将GATSBY_CONCURRENT_DOWNLOAD环境变量设置为16(或更低(,如本论坛中所述

这应该可以避免您达到Netlify内存限制

相关内容

  • 没有找到相关文章

最新更新