Gatsby: 升级到2.0.84后,在`async-requires`中带有“意外令牌”之后,构建失败

创建于 2019-01-21  ·  81评论  ·  资料来源: gatsbyjs/gatsby

描述

rm -rf .cache && rm -rf public && gatsby-build 2.0.83下运行

重现步骤

我唯一正在运行的是gatsby build 。 降级到2.0.83后,问题消失了。

预期结果

构建应该成功完成

实际结果

生成退出并出现以下错误:

success onPostBootstrap — 0.202 s

info bootstrap finished - 6.171 s


error Generating JavaScript bundles failed


  Error: ./.cache/async-requires.js 8:11
  Module parse failed: Unexpected token (8:11)
  You may need an appropriate loader to handle this file type.
  | exports.components = {
  |   "component---node-modules-gatsby-plugin-offline-app-shell-js": function componentNodeModulesGatsbyPluginOfflineAppShellJs() {
  >     return import("/Users/dereklindahl/Work/APP/node_modules/gatsby-plugin-offline/app-shell.js"
  |     /* webpackChunkName: "component---node-modules-gatsby-plugin-offline-app-shell-js" */
  |     );
   @ ./.cache/production-app.js 18:0-45 21:23-36 26:23-36

环境

npx gatsby info -- --clipboard                 

  System:
    OS: macOS High Sierra 10.13.6
    CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
    Shell: 5.4.2 - /usr/local/bin/zsh
  Binaries:
    Node: 10.14.0 - ~/.nodenv/versions/10.14.0/bin/node
    Yarn: 1.12.3 - /usr/local/bin/yarn
    npm: 6.4.1 - ~/.nodenv/versions/10.14.0/bin/npm
  Languages:
    Python: 2.7.10 - /usr/bin/python
  Browsers:
    Chrome: 71.0.3578.98
    Firefox: 63.0.3
    Safari: 12.0.2
  npmPackages:
    gatsby: 2.0.84 => 2.0.84 
    gatsby-image: ^2.0.25 => 2.0.25 
    gatsby-mdx: ^0.2.0 => 0.2.0 
    gatsby-plugin-canonical-urls: ^2.0.8 => 2.0.8 
    gatsby-plugin-google-analytics: ^2.0.8 => 2.0.8 
    gatsby-plugin-manifest: ^2.0.13 => 2.0.13 
    gatsby-plugin-netlify: ^2.0.6 => 2.0.6 
    gatsby-plugin-netlify-cache: ^1.0.0 => 1.0.0 
    gatsby-plugin-offline: ^2.0.21 => 2.0.21 
    gatsby-plugin-react-helmet: ^3.0.5 => 3.0.5 
    gatsby-plugin-sharp: ^2.0.17 => 2.0.17 
    gatsby-plugin-sitemap: ^2.0.4 => 2.0.4 
    gatsby-plugin-sri: ^1.0.4 => 1.0.4 
    gatsby-plugin-styled-components: ^3.0.4 => 3.0.4 
    gatsby-plugin-zopfli: ^1.0.2 => 1.0.2 
    gatsby-source-filesystem: ^2.0.12 => 2.0.12 
    gatsby-transformer-sharp: ^2.1.10 => 2.1.10 

我看到#10038听起来很熟悉,但是我的Webpack配置并不有趣:

// gatsby-node.js
exports.onCreateWebpackConfig = ({ actions }) => {
  actions.setWebpackConfig({
    module: {
      rules: [
        {
          test: /\.ogv$/,
          use: [
            {
              loader: require.resolve(`url-loader`),
              options: { limit: 10000, name: 'static/[name]-[hash].[ext]' }
            }
          ]
        }
      ]
    },
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src/components')
      },
      modules: [path.resolve(__dirname, 'src'), 'node_modules']
    }
  })
}

注释掉该阻止并不能解决该错误。

如果我将gatsby-plugin-offline替换gatsby-plugin-remove-serviceworker ,问题仍然存在,但是异步导入不同。

FWIW,我没有注意到2.0.83或2.0.84版本中async-require.js内容的差异,升级gatsby-plugin-offline也没有差异。

needs reproduction question or discussion

最有用的评论

一种解决方法是使用Yarn而不是npm安装依赖项,这似乎在导入npm锁定文件后起作用。

所有81条评论

2.0.62升级到2.0.91后,我遇到类似的错误。

在我的情况下, gatsby develop工作正常,但gatsby build错误出无论是在template.js页面(如果包括我的话)或404.js (如果删除来自gatsby-node createPages片段):

error Generating JavaScript bundles failed

Error: ./.cache/async-requires.js 8:11
  Module parse failed: Unexpected token (8:11)
  You may need an appropriate loader to handle this file type.
  | exports.components = {
  |   "component---src-templates-template-js": function componentSrcTemplatesTemplateJs() {
  >     return import("/Users/michael/Sites/projects/gatsby-starter/src/templates/template.js"
  |     /* webpackChunkName: "component---src-templates-template-js" */  |     );
   @ ./.cache/production-app.js 18:0-45 21:23-36 26:23-36

要么

error Generating JavaScript bundles failed

Error: ./.cache/async-requires.js 8:11
  Module parse failed: Unexpected token (8:11)
  You may need an appropriate loader to handle this file type.
  | exports.components = {
  |   "component---src-pages-404-js": function componentSrcPages404Js()   {
  >     return import("/Users/michael/Sites/projects/gatsby-starter/src/pages/404.js"
  |     /* webpackChunkName: "component---src-pages-404-js" */
  |     );
   @ ./.cache/production-app.js 18:0-45 21:23-36 26:23-36

升级gatsby之前,一切正常。 ♂️

@dlindahl @ooloth

您能否链接至此的最小复制品?

我使用Gatsby v 2.0.55遇到了相同的错误,其中在.npmrc中禁用package-lock.json。 该站点每天都是由干净的工作区构建的。 一天有效,第二天却没有。 我猜该错误与某些瞬态依赖关系已更改。

当我将gatsbyv2.0.91升级到v2.0.93v2.0.92 )时出现相同的问题

嗨,我想说的是我目前也遇到了这个问题,但正在努力为它建立最小的复制品。

当前在我的存储库中运行npm update确实会导致构建失败,但是并不能用于我的个人网站

我会一直四处挖掘,直到找到导致它的原因或其他人发现它为止。 如果可以将其隔离干净,我将在此发布。

谢谢!

同样在这里!
我已经键入npm update -g npm来获取npm 6.7.0版本,并且我有gatsby 2.0.98。

gatsby插件离线版本-> 2.0.21

存在此问题的存储库:到

还可以用npm ls列出已安装的依赖项并运行node --version吗?

在这里,二等分可能也会有所帮助。 我将在几分钟后测试该存储库。

确定在这里同样的错误。 我将一分为二。

似乎它在所有版本中都发生,因此它可能是插件或其他依赖项。
将进一步测试。

我想我找到了原因。 我将提供补丁程序和PR。

@omrllm (盖茨比2.0.60的补丁程序)

patch-package
--- a/node_modules/gatsby/dist/internal-plugins/query-runner/pages-writer.js
+++ b/node_modules/gatsby/dist/internal-plugins/query-runner/pages-writer.js
@@ -86,9 +86,9 @@ const preferDefault = m => m && m.default || m
     let asyncRequires = `// prefer default export if available
 const preferDefault = m => m && m.default || m
 \n`;
-    asyncRequires += `exports.components = {\n${components.map(c => `  "${c.componentChunkName}": () => import("${(0, _path.joinPath)(c.component)}" /* webpackChunkName: "${c.componentChunkName}" */)`).join(`,\n`)}
+    asyncRequires += `exports.components = {\n${components.map(c => `  "${c.componentChunkName}": () => require("${(0, _path.joinPath)(c.component)}" /* webpackChunkName: "${c.componentChunkName}" */)`).join(`,\n`)}
 }\n\n`;
-    asyncRequires += `exports.data = () => import("${(0, _path.joinPath)(program.directory, `.cache`, `data.json`)}")\n\n`;
+    asyncRequires += `exports.data = () => require("${(0, _path.joinPath)(program.directory, `.cache`, `data.json`)}")\n\n`;

     const writeAndMove = (file, data) => {
       const destination = (0, _path.joinPath)(program.directory, `.cache`, file);

通过将import更改require它应该可以工作。 可能只是缺少了一个加载器,但是当ESM方式产生问题并将exportsimport混合在一起时,为什么无论如何在这里使用import从来都不是一个好主意。

+ [email protected]
+ [email protected]
+ [email protected]
+ [email protected]
+ [email protected]
+ [email protected]
added 9 packages from 3 contributors, removed 4 packages, updated 92 packages and audited 43569 packages in 200.269s
diff 23.cache/ .cache/
Only in 23.cache/: .sonarlint
Common subdirectories: 23.cache/__tests__ and .cache/__tests__
Common subdirectories: 23.cache/caches and .cache/caches
Common subdirectories: 23.cache/commonjs and .cache/commonjs
diff 23.cache/data.json .cache/data.json
1c1
< {"pages":[{"componentChunkName":"component---src-pages-index-js","jsonName":"index","path":"/"},{"componentChunkName":"component---src-pages-404-js","jsonName":"404-html-516","path":"/404.html"},{"componentChunkName":"component---src-pages-404-js","jsonName":"404-22d","path":"/404/"},{"componentChunkName":"component---src-pages-about-js","jsonName":"about-f34","path":"/about/"},{"componentChunkName":"component---src-pages-contact-js","jsonName":"contact-26a","path":"/contact/"}],"dataPaths":{"404-22d":"657/path---404-22-d-bce-yc2HAWbdDECy3NCKIhFOCg1lY8","404-html-516":"84/path---404-html-516-62a-yc2HAWbdDECy3NCKIhFOCg1lY8","about-f34":"691/path---about-f-34-4c2-WV9OHhcgC975Z2f0az9WK5Dpl0Y","contact-26a":"662/path---contact-26-a-cd9-SNoLKPyPsqQ59X6yAuuT79ALOJc","index":"612/path---index-6a9-j0JKW3rrllGOOtWKwyNn0ujHMk"}}
\ No newline at end of file
---
> {"pages":[{"componentChunkName":"component---src-pages-index-js","jsonName":"index","path":"/"},{"componentChunkName":"component---src-pages-404-js","jsonName":"404-html-516","path":"/404.html"},{"componentChunkName":"component---src-pages-404-js","jsonName":"404-22d","path":"/404/"},{"componentChunkName":"component---src-pages-about-js","jsonName":"about-f34","path":"/about/"},{"componentChunkName":"component---src-pages-contact-js","jsonName":"contact-26a","path":"/contact/"}],"dataPaths":{"404-22d":"657/path---404-22-d-bce-yc2HAWbdDECy3NCKIhFOCg1lY8","404-html-516":"84/path---404-html-516-62a-yc2HAWbdDECy3NCKIhFOCg1lY8","about-f34":"691/path---about-f-34-4c2-WV9OHhcgC975Z2f0az9WK5Dpl0Y","contact-26a":"662/path---contact-26-a-cd9-SNoLKPyPsqQ59X6yAuuT79ALOJc","index":"770/path---index-6a9-dVi4vZoL0B52PVt3C79b9kQk"}}
\ No newline at end of file
diff 23.cache/default-html.js .cache/default-html.js
4,31c4,29
< export default class HTML extends React.Component {
<   render() {
<     return (
<       <html {...this.props.htmlAttributes}>
<         <head>
<           <meta charSet="utf-8" />
<           <meta httpEquiv="x-ua-compatible" content="ie=edge" />
<           <meta
<             name="viewport"
<             content="width=device-width, initial-scale=1, shrink-to-fit=no"
<           />
<           {this.props.headComponents}
<         </head>
<         <body {...this.props.bodyAttributes}>
<           {this.props.preBodyComponents}
<           <noscript key="noscript" id="gatsby-noscript">
<             This app works best with JavaScript enabled.
<           </noscript>
<           <div
<             key={`body`}
<             id="___gatsby"
<             dangerouslySetInnerHTML={{ __html: this.props.body }}
<           />
<           {this.props.postBodyComponents}
<         </body>
<       </html>
<     )
<   }
---
> export default function HTML(props) {
>   return (
>     <html {...props.htmlAttributes}>
>       <head>
>         <meta charSet="utf-8" />
>         <meta httpEquiv="x-ua-compatible" content="ie=edge" />
>         <meta
>           name="viewport"
>           content="width=device-width, initial-scale=1, shrink-to-fit=no"
>         />
>         {props.headComponents}
>       </head>
>       <body {...props.bodyAttributes}>
>         {props.preBodyComponents}
>         <noscript key="noscript" id="gatsby-noscript">
>           This app works best with JavaScript enabled.
>         </noscript>
>         <div
>           key={`body`}
>           id="___gatsby"
>           dangerouslySetInnerHTML={{ __html: props.body }}
>         />
>         {props.postBodyComponents}
>       </body>
>     </html>
>   )
Common subdirectories: 23.cache/fragments and .cache/fragments
Common subdirectories: 23.cache/json and .cache/json
diff 23.cache/navigation.js .cache/navigation.js
37c37
< const onPreRouteUpdate = location => {
---
> const onPreRouteUpdate = (location, prevLocation) => {
39c39
<     apiRunner(`onPreRouteUpdate`, { location })
---
>     apiRunner(`onPreRouteUpdate`, { location, prevLocation })
43c43
< const onRouteUpdate = location => {
---
> const onRouteUpdate = (location, prevLocation) => {
45c45
<     apiRunner(`onRouteUpdate`, { location })
---
>     apiRunner(`onRouteUpdate`, { location, prevLocation })
136c136
<     onPreRouteUpdate(props.location)
---
>     onPreRouteUpdate(props.location, null)
140c140
<     onRouteUpdate(this.props.location)
---
>     onRouteUpdate(this.props.location, null)
145c145
<       onRouteUpdate(this.props.location)
---
>       onRouteUpdate(this.props.location, prevProps.location)
151c151
<       onPreRouteUpdate(this.props.location)
---
>       onPreRouteUpdate(this.props.location, prevProps.location)
diff 23.cache/static-entry.js .cache/static-entry.js
55c55,59
<     <meta name="generator" content={`Gatsby ${gatsbyVersion}`} />,
---
>     <meta
>       name="generator"
>       content={`Gatsby ${gatsbyVersion}`}
>       key={`generator-${gatsbyVersion}`}
>     />,
354,360c358,366
<   const bodyScripts = scripts.filter(s => s.rel !== `prefetch`).map(s => {
<     const scriptPath = `${__PATH_PREFIX__}/${JSON.stringify(s.name).slice(
<       1,
<       -1
<     )}`
<     return <script key={scriptPath} src={scriptPath} async />
<   })
---
>   const bodyScripts = scripts
>     .filter(s => s.rel !== `prefetch`)
>     .map(s => {
>       const scriptPath = `${__PATH_PREFIX__}/${JSON.stringify(s.name).slice(
>         1,
>         -1
>       )}`
>       return <script key={scriptPath} src={scriptPath} async />
>     })

在更新程序和新版本后进行比较@madelyneriksen

patch-package
--- a/node_modules/gatsby/dist/internal-plugins/query-runner/pages-writer.js
+++ b/node_modules/gatsby/dist/internal-plugins/query-runner/pages-writer.js
@@ -88,9 +88,9 @@ const preferDefault = m => m && m.default || m
     let asyncRequires = `// prefer default export if available
 const preferDefault = m => m && m.default || m
 \n`;
-    asyncRequires += `exports.components = {\n${components.map(c => `  "${c.componentChunkName}": () => import("${(0, _path.joinPath)(c.component)}" /* webpackChunkName: "${c.componentChunkName}" */)`).join(`,\n`)}
+    asyncRequires += `exports.components = {\n${components.map(c => `  "${c.componentChunkName}": () => require("${(0, _path.joinPath)(c.component)}" /* webpackChunkName: "${c.componentChunkName}" */)`).join(`,\n`)}
 }\n\n`;
-    asyncRequires += `exports.data = () => import(/* webpackChunkName: "pages-manifest" */ "${(0, _path.joinPath)(program.directory, `.cache`, `data.json`)}")\n\n`;
+    asyncRequires += `exports.data = () => require(/* webpackChunkName: "pages-manifest" */ "${(0, _path.joinPath)(program.directory, `.cache`, `data.json`)}")\n\n`;

     const writeAndMove = (file, data) => {
       const destination = (0, _path.joinPath)(program.directory, `.cache`, file);

这应该适用于.98

也许我走在错误的轨道上,更改导致测试失败https://github.com/gatsbyjs/gatsby/pull/11331

尚不知道为什么。

所以它仍然不起作用,对吗?

构建脚本成功完成了我建议的更改。 但是我不确定这是否是正确的解决方案。 因此,请对其进行测试和审查。

嗯,还是由于新的预设?
https://github.com/gatsbyjs/gatsby/commit/69faca0bff0e2c04e6b3be50bba087284c3dbf6b#diff -a30bb413b08d8091d9187909b256c943

插件数组正确吗?

这个问题是否还会出现在新的Gatsby新项目中,并且可以通过CI测试重现吗?

npm update ,问题消失了

请提供已安装依赖关系的列表(更新前后)。

@DanielRuf ,我无法复制它,我猜那是

一种解决方法是使用Yarn而不是npm安装依赖项,这似乎在导入npm锁定文件后起作用。

您可以在这里找到我的npm ls和gatsby v2.0.91(构建成功)和v2.0.93(构建失败): https ://gist.github.com/cyrildurand/f4b70abff19288117ea3996500532774

我仍然有gatsby 2.0.103的问题

您是否也尝试使用yarn安装依赖项?

@cyrildurand
安装npm时是否遇到此错误?
2019-01-29 4 50 27
我也遇到了同样的问题,但是将arcon的版本升级到6.0效果很好。

安装npm时是否遇到此错误

这只是警告,与盖茨比问题无关。

安装acorn后出现相同错误

它适用于yarn 。 我用yarn list输出更新了要点

安装橡子后同样的错误

哪个错误?

我尝试升级@ seonim-ryu建议的acorn并尝试运行gatsby build并出现相同的“意外令牌”错误(此问题的第一条消息中的错误)

如果我使用yarn,问题将消失, gatsby build命令成功。

以前的橡子版本也会发生这种情况吗? 还是这不是原因?

您尝试了我建议的修复程序吗? 不知道这是否会破坏任何东西。

它也因先前版本的橡子而失败,我认为这与它无关。

现在,我已经安装了依赖项,但是我不确定如何应用您建议的修复程序,现在可以正常工作。

转到node_modules / gatsby / dist / internal-plugins / query-runner / pages-writer.js并将两个import(更改require( ,另请参见https://github.com/gatsbyjs / gatsby / issues / 11198#issuecomment -457915157

它与修复一起工作

修复程序有什么坏的吗? 失败的CI构建看起来并不好。

可能是一个单独的问题,但是在升级到最新的Gatsby(2.0.106)并按照文档('src / pages / 404.js')添加404页面后,出现了类似的错误。 开发可以正常运行,但是构建失败。

将404页移到其自己的文件夹('src / pages / 404 / index.js')中,此错误已在我端解决,并按预期工作(在本地以及部署到Netlify时)。

我通过删除package-lock.json文件并运行npm install 。 新生成的package-lock.json文件有很多差异。
不知道到底会发生什么。

在我拥有的几个不同站点中遇到相同的问题。 有些具有完全相同的依赖关系和版本...一个会遇到错误,一个不会。 我相信它大约在2.0.98左右开始发生,直到2.0.106。 我曾尝试删除node_modules,.cache和公用文件夹,但这也无济于事。 仅发生在构建上,而不发生在开发上。

@cyrildurand
我将package-lock.json重命名为其他名称,然后npm install编辑了所有内容,但我又得到了:

error Generating JavaScript bundles failed


  Error: ./.cache/async-requires.js 8:11
  Module parse failed: Unexpected token (8:11)
  You may need an appropriate loader to handle this file type.
  | exports.components = {
  |   "component---node-modules-gatsby-plugin-offline-app-shell-js": function componentNodeModulesGatsbyPluginOfflineAppShellJs() {
  >     return import("/home/foldername/abcrypto/node_modules/gatsby-plugin-offline/app-shell.js"
  |     /* webpackChunkName: "component---node-modules-gatsby-plugin-offline-app-shell-js" */
  |     );
   @ ./.cache/production-app.js 18:0-45 21:23-36 26:23-36

您是否清理了node_modules文件夹?

你是怎样做的? :(

npm prune node_modules

还是我手动删除node_modules文件夹中的所有内容?

编辑:我已经重命名了node_modules文件夹,现在它可以工作:+1:

  • 将package-lock.json重命名为其他名称
  • 将node_modules文件夹重命名为其他名称
  • 主文件夹中的npm install

谢谢@cyrildurand
@DanielRuf建议之后编辑

只需将其重命名即可进行备份。

那么,这真的只是一个过时的依赖问题吗?

我多次删除了节点模块,但对我而言从来没有修复过。 唯一有效的方法是yarn或上面的补丁文件。

@krazik ,您是否删除/重命名package-lock.json?

只是为了确保我再次尝试过,并删除两者都可以克服上面的错误,但是现在遇到了

错误:找不到模块“ core-js / modules / es6.regexp.to-string”
错误:找不到模块“ core-js / modules / es6.regexp.to-string”

为建设和发展。

error Cannot find module 'core-js/modules/es6.regexp.to-string'


  Error: Cannot find module 'core-js/modules/es6.regexp.to-string'

  - loader.js:611 Function.Module._resolveFilename
    internal/modules/cjs/loader.js:611:15

  - loader.js:537 Function.Module._load
    internal/modules/cjs/loader.js:537:25

  - loader.js:665 Module.require
    internal/modules/cjs/loader.js:665:17

  - helpers.js:20 require
    internal/modules/cjs/helpers.js:20:18

  - render-page.js:3 webpackUniversalModuleDefinition
    /Users/rylanhazelton/dev/Admin/public/render-page.js:3:170

  - render-page.js:10 Object.<anonymous>
    /Users/rylanhazelton/dev/Admin/public/render-page.js:10:3

  - loader.js:736 Module._compile
    internal/modules/cjs/loader.js:736:30

  - loader.js:747 Object.Module._extensions..js
    internal/modules/cjs/loader.js:747:10

  - loader.js:628 Module.load
    internal/modules/cjs/loader.js:628:32

  - loader.js:568 tryModuleLoad
    internal/modules/cjs/loader.js:568:12

  - loader.js:560 Function.Module._load
    internal/modules/cjs/loader.js:560:3

  - loader.js:665 Module.require
    internal/modules/cjs/loader.js:665:17

  - helpers.js:20 require
    internal/modules/cjs/helpers.js:20:18

  - worker.js:32 Promise
    [Admin]/[gatsby]/dist/utils/worker.js:32:35

  - debuggability.js:313 Promise._execute
    [Admin]/[bluebird]/js/release/debuggability.js:313:9

  - promise.js:483 Promise._resolveFromExecutor
    [Admin]/[bluebird]/js/release/promise.js:483:18


error UNHANDLED REJECTION


  Error: Cannot find module 'core-js/modules/es6.regexp.to-string'

  - loader.js:611 Function.Module._resolveFilename
    internal/modules/cjs/loader.js:611:15

  - loader.js:537 Function.Module._load
    internal/modules/cjs/loader.js:537:25

  - loader.js:665 Module.require
    internal/modules/cjs/loader.js:665:17

  - helpers.js:20 require
    internal/modules/cjs/helpers.js:20:18

  - render-page.js:3 webpackUniversalModuleDefinition
    /Users/rylanhazelton/dev/Admin/public/render-page.js:3:170

  - render-page.js:10 Object.<anonymous>
    /Users/rylanhazelton/dev/Admin/public/render-page.js:10:3

  - loader.js:736 Module._compile
    internal/modules/cjs/loader.js:736:30

  - loader.js:747 Object.Module._extensions..js
    internal/modules/cjs/loader.js:747:10

  - loader.js:628 Module.load
    internal/modules/cjs/loader.js:628:32

  - loader.js:568 tryModuleLoad
    internal/modules/cjs/loader.js:568:12

  - loader.js:560 Function.Module._load
    internal/modules/cjs/loader.js:560:3

  - loader.js:665 Module.require
    internal/modules/cjs/loader.js:665:17

  - helpers.js:20 require
    internal/modules/cjs/helpers.js:20:18

  - worker.js:32 Promise
    [Admin]/[gatsby]/dist/utils/worker.js:32:35

  - debuggability.js:313 Promise._execute
    [Admin]/[bluebird]/js/release/debuggability.js:313:9

  - promise.js:483 Promise._resolveFromExecutor
    [Admin]/[bluebird]/js/release/promise.js:483:18

尝试关闭您的编辑器,删除.cache,public,node_modules和package-lock.json。 然后执行npm安装。

我很确定这只是NPM的一些时髦的包装解析。

我确实设法通过删除锁文件和node_modules来在我的站点上整理出依赖项。 我无法在损坏的网站之外重现它。

删除我的package-lock.jsonnode_modules并使用yarn我又遇到了关于terser-webpack-plugin cannot call minify of undefined (类似的东西)。 为我解决了。

我猜想Node.js生态系统确实是最快的生态系统;-)

最新的terser更新(一个小时前发布)破坏了此插件。

因此,这是一个新问题(依赖项)。

我可以确认这是两个不同的问题,我遇到了两个问题: https :

Terser错误来自这些行

  const {
    error,
    map,
    code,
    warnings
  } = _terser.default.minify({
    [file]: input
  }, terserOptions);

如果您仅用_terser.minify代替_terser.default.minify _terser.minify

我在Travis CI版本中也遇到了这个问题。 即使使用yarn也无法解决问题。 在正确修复之前,我可以使用任何快速修补程序吗? 谢谢

Terser错误应立即解决

terser-webpack-plugin已修复,我们用新版本的terser-webpack-plugin发布了2.0.112。

我不确定这是否相关,但是您可以尝试更新吗?

同时, @ DanielRuf @dlindahl是否可以链接到您所看到的问题的最小复制?

我可以确认@sidharthachatterjee ,升级到特定的[email protected]解决了我在Gitlab CI上的问题。

Terser错误应立即解决

确认。

让我们结束这个。 请发表评论,我们是否可以提供进一步帮助,或者是否“不确定”要修复。

谢谢大家!

此问题被打开的原始错误仍然存​​在:

Error: ./.cache/async-requires.js 8:11
Module parse failed: Unexpected token (8:11)

@ gr2m您可以提供复制品吗?

无论如何-我会重新打开,谢谢!

我有完全一样的问题。
模块解析失败:意外的令牌(8:11)
您可能需要适当的加载程序来处理此文件类型

纱线定型对我有用。

删除.cache / public / node_modules无效。

在运行npm update之后,这个问题对我开始了。

同样的问题在这里。

    "@magicsoup.io/stock": "0.0.11",
    "@zauberware/react-scroll-to": "^0.1.1",
    "@zauberware/react-svg-assets": "^0.10.2",
    "babel-plugin-styled-components": "^1.10.0",
    "gatsby": "^2.0.115",
    "gatsby-image": "^2.0.29",
    "gatsby-plugin-htaccess": "^1.0.8",
    "gatsby-plugin-manifest": "^2.0.17",
    "gatsby-plugin-offline": "^2.0.22",
    "gatsby-plugin-react-helmet": "^3.0.6",
    "gatsby-plugin-sharp": "^2.0.20",
    "gatsby-plugin-sitemap": "^2.0.5",
    "gatsby-plugin-styled-components": "^3.0.5",
    "gatsby-plugin-web-font-loader": "^1.0.4",
    "gatsby-source-filesystem": "^2.0.20",
    "gatsby-transformer-json": "^2.1.8",
    "gatsby-transformer-remark": "^2.2.4",
    "gatsby-transformer-sharp": "^2.1.13",
    "marksy": "^6.1.0",
    "prop-types": "^15.6.2",
    "react": "^16.7.0",
    "react-dom": "^16.7.0",
    "react-helmet": "^5.2.0",
    "react-i18next": "^10.0.0",
    "react-obfuscate": "^3.0.0",
    "react-slick": "^0.23.2",
    "styled-components": "^4.1.3",
    "styled-normalize": "^8.0.6",
    "styled-system": "^3.2.1",

尝试从src / templates加载模板

Error: ./.cache/async-requires.js 8:11
  Module parse failed: Unexpected token (8:11)
  You may need an appropriate loader to handle this file type.
  | exports.components = {
  |   "component---src-templates-markdown-template-js": function componentSrcTemplatesMarkdownTemplateJs() {
  >     return import("/Users/simon/workspaces/web/altstadtdomizil/src/templates/markdownTemplate.js"
  |     /* webpackChunkName: "component---src-templates-markdown-template-js" */
  |     );
   @ ./.cache/production-app.js 18:0-45 21:23-36 26:23-36

gatsby-node.js

exports.createPages = ({ actions, graphql }) => {
  const { createPage } = actions

  const blogPostTemplate = path.resolve(`src/templates/markdownTemplate.js`)

  return graphql(`
    {
      allMarkdownRemark(
        sort: { order: DESC, fields: [frontmatter___title] }
        limit: 1000
      ) {
        edges {
          node {
            frontmatter {
              path
            }
          }
        }
      }
    }
  `).then(result => {
    if (result.errors) {
      return Promise.reject(result.errors)
    }

    result.data.allMarkdownRemark.edges.forEach(({ node }) => {
      createPage({
        path: node.frontmatter.path,
        component: blogPostTemplate,
        context: {}, // additional data can be passed via context
      })
    })
  })
}

如果我注释掉gatsby-node.js,则会收到此错误:

  Error: ./.cache/async-requires.js 8:11
  Module parse failed: Unexpected token (8:11)
  You may need an appropriate loader to handle this file type.
  | exports.components = {
  |   "component---src-pages-404-js": function componentSrcPages404Js() {
  >     return import("/Users/simon/workspaces/web/altstadtdomizil/src/pages/404.js"
  |     /* webpackChunkName: "component---src-pages-404-js" */
  |     );
   @ ./.cache/production-app.js 18:0-45 21:23-36 26:23-36

返回导入(

请参阅其他评论。

从2.0.115升级到2.0.116或2.0.117时,它会显示在badge / shields#2947中。

我最近合并了badge / shields#2949,将babel-preset-gatsby从0.1.6更新为0.1.7,尽管我曾尝试过降级进行黑客攻击,但并不能解决问题。

该问题已在CI中发现,并且一直在那里出现。 我们的配置项不会保留.cache ,因此可以排除。

  Error: ./.cache/async-requires.js 8:11
  Module parse failed: Unexpected token (8:11)
  You may need an appropriate loader to handle this file type.
  | exports.components = {
  |   "component---frontend-components-main-js": function componentFrontendCompo  nentsMainJs() {
  >     return import("/home/circleci/project/frontend/components/main.js"
  |     /* webpackChunkName: "component---frontend-components-main-js" */
  |     );
   @ ./.cache/production-app.js 18:0-45 21:23-36 26:23-36

https://circleci.com/gh/badges/shields/39885

我认为这可能是问题所在:webpack / webpack#8656。

补充:症状匹配和时间适合。

screen shot 2019-02-07 at 9 17 12 pm

screen shot 2019-02-07 at 9 17 19 pm

@paulmelnikow好抓住。 这就是为什么我们建议您在不必使用ESM的情况下使用CJS的原因-在捆绑器中,它仍然不是100%可靠的。 而另一种方式应该仍然有效。

那么将webpack固定在根package.json中应该起作用吗?

这个js也是为什么JS生态系统中的SemVer被完全打破的恕我直言。 (深度)deps的自动更新,因为锁定文件仅在根级别起作用。

要清楚, acorn和npm解决deptree的方式是问题和原因。

https://github.com/webpack/webpack/issues/8656#issuecomment -456010969

我可以重现这一点(我们仍在使用纱线的另一个原因)。

我不确定我是否同意这一评估。 这可能以npm表示,而不是由于解析方式的不同而产生的纱线,但是4.29.3是在软件包声明依赖于^ 4.12.0时完全正确的版本。 这就是插入号的意思。 如果Gatsby想要锁定特定版本,欢迎这样做,在这种情况下,npm将兑现它。

Webpack是Gatsby的依赖,而不是对等依赖。

问题是npm中的提升(在Yarn中不同),因此无法正确加载acorn 。 请参阅Tobias社区帖子和链接的评论。

我觉得我需要你更好地解释。 我略过了这些线程,但是在这里看不到如何应用。

我不知道是什么原因导致Webpack中的错误; 但是,如果我们同意Gatsby不应该使用4.29.3,则需要更改插入符号的依赖性。

它适用于yarn,与特定的依赖项和deptree计算结合使用时,npm只是一个问题。 参见Tobias的PR。

参见https://github.com/npm/cli/pull/147/files

Aiiiee陷阱。 这是npm中的对等依赖项错误,这是导致webpack 4.29无法正常工作的原因。

我们无法阻止的是webpack 4.29的安装。 而且我不确定最终用户是否有一种简单的方法来锁定Webpack版本。 npm没有提供执行此操作的方法,因此用户将不得不使用第三方工具npm-force-resolutions之类的东西

参见npm / cli#152; 看起来我们无法期望获得快速解决方案。

现在2.0.118附带了创可贴,npm用户应该可以了,显然​​无论如何不能使用webpack4.29.x。

我是否可以让纱线用户根据需要使用resolutions强制gatsby使用更高范围的版本?

@paulmelnikow正确-但确实不是必须的,而且我不确定这样做是否有特殊的好处。

我们将尽快更新固定的依赖关系(现在紧跟着npm问题),因此对于npm用户来说应该只是暂时的。

感谢您的修复!

_Now_我想可以解决这个问题了:)

确认已在2.0.118版本中修复!

令人赞叹的是。 谢谢大家所做的出色工作!

大家好! 我想知道你们是否可以让npm install gatsby@webpack-acorn旋转。 我们想将webpack升级到最新版本,但是我们不确定这是否仍然是问题。 我无法复制它,但我们宁愿安全而不愿后悔。

嗨@wardpeet! 感谢您与我们联系。

我在这里创建了一个分支:badges / shields#3572

看起来仍然是一个问题: https :

在本地复制的步骤是克隆该分支并运行npm ci然后运行npm run build 。 如果您愿意,可以执行此操作,或者ping我,我可以更新PR分支。

@paulmelnikow非常感谢! 您能否也告诉我您使用的是哪个节点和npm版本,以便我可以在您的安装程序中运行它,以防它对我有用。

这是我在本地得到的:

~/c/shields (bump-webpack-rc|✔) $ node --version
v10.13.0
~/c/shields (bump-webpack-rc|✔) $ npm --version
6.9.0

在CI中,它也在节点8中发生(不确定确切的npm版本)。

在两种环境中都可以重现该问题。

感谢您的关注!

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

dustinhorton picture dustinhorton  ·  3评论

theduke picture theduke  ·  3评论

KyleAMathews picture KyleAMathews  ·  3评论

3CordGuy picture 3CordGuy  ·  3评论

magicly picture magicly  ·  3评论