Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.0k views
in Technique[技术] by (71.8m points)

npm - ERROR #98123 WEBPACK: Generating development JavaScript bundle failed - unexpected token

I have cloned my repository an then install all packages via npm. When i try to start mu program with gatsby develop i get this error in all files in templates directory.

enter image description here

I've already cleared chache, deleted node_modules and public folders, re-install packages and so on, but nothing worked.

This is is info, which I get from gatsby info:

  System:
    OS: macOS 11.1
    CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 14.0.0 - ~/.nvm/versions/node/v14.0.0/bin/node
    Yarn: 1.13.0 - ~/.npm-global/bin/yarn
    npm: 6.14.4 - ~/.nvm/versions/node/v14.0.0/bin/npm
  Languages:
    Python: 2.7.16 - /usr/bin/python
  Browsers:
    Chrome: 87.0.4280.141
    Firefox: 78.0.2
    Safari: 14.0.2
  npmPackages:
    gatsby: ^2.30.1 => 2.31.1
    gatsby-awesome-pagination: ^0.3.6 => 0.3.6
    gatsby-image: ^2.5.0 => 2.10.0
    gatsby-plugin-eslint: ^2.0.8 => 2.0.8
    gatsby-plugin-fontawesome-css: ^1.0.0 => 1.0.0
    gatsby-plugin-manifest: ^2.6.1 => 2.11.0
    gatsby-plugin-netlify-cms: ^4.5.0 => 4.9.0
    gatsby-plugin-offline: ^3.4.0 => 3.9.0
    gatsby-plugin-react-helmet: ^3.4.0 => 3.9.0
    gatsby-plugin-sharp: ^2.8.0 => 2.13.1
    gatsby-plugin-styled-components: ^3.5.0 => 3.9.0
    gatsby-plugin-typography: ^2.10.0 => 2.11.0
    gatsby-source-filesystem: ^2.5.0 => 2.10.0
    gatsby-transformer-remark: ^2.12.0 => 2.15.0
    gatsby-transformer-sharp: ^2.6.0 => 2.11.0

Does anyone have similar problem, or know how to solve it?

question from:https://stackoverflow.com/questions/65852750/error-98123-webpack-generating-development-javascript-bundle-failed-unexpect

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It's not a matter of dependencies or configuration, you have a typo in your project. It seems that somewhere in your JavaScript files (maybe in the templates folder) you have a . (dot) that is breaking your code.

To enable optional chaining in any JavaScript project, since it's not a standard feature, you need to:

  • Install the dependency (@babel/plugin-proposal-optional-chaining):
    npm install --save-dev @babel/plugin-proposal-optional-chaining
    
    Or:
    yarn add @babel/plugin-proposal-optional-chaining --dev
    
  • Enable it in your Babel configuration. In Gatsby, you can create a babel.config.js (or .babelrc) in the root of your project to customize Babel's configuration:
    {
       "plugins": [
         ["@babel/plugin-proposal-optional-chaining"]
       ],
       "presets": [
         [
           "babel-preset-gatsby",
           {
             "targets": {
               "browsers": [">0.25%", "not dead"]
             }
           }
         ]
       ]
    }
    

Fixed by:

problem was my package-lock.json. After we fixed it, everything works properly :) nevermind


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...