Home
Support Forums

Webpack babel/@polifill

Hello I’m having an issue trying to publish

2:56:11 PM: ERROR in multi @babel/polyfill ./src/index.js
2:56:11 PM: Module not found: Error: Can’t resolve ‘./src/index.js’ in ‘/opt/build/repo’
@ multi @babel/polyfill ./src/index.js main[1]

            2:55:12 PM: Build ready to start
            2:55:14 PM: build-image version: 53b83b6bede2920f236b25b6f5a95334320dc849
            2:55:14 PM: build-image tag: v3.6.0
            2:55:14 PM: buildbot version: dc0a2b81d00d8f0151c0b6d6eab301febfb9ab68
            2:55:14 PM: Fetching cached dependencies
            2:55:14 PM: Failed to fetch cache, continuing with build
            2:55:14 PM: Starting to prepare the repo for build
            2:55:14 PM: No cached dependencies found. Cloning fresh repo
            2:55:14 PM: git clone https://github.com/hiad/pager-test
            2:55:16 PM: Preparing Git Reference refs/heads/master
            2:55:17 PM: Starting build script
            2:55:18 PM: Installing dependencies
            2:55:18 PM: Python version set to 2.7
            2:55:19 PM: v12.18.0 is already installed.
            2:55:19 PM: Now using node v12.18.0 (npm v6.14.4)
            2:55:20 PM: Started restoring cached build plugins
            2:55:20 PM: Finished restoring cached build plugins
            2:55:20 PM: Attempting ruby version 2.7.1, read from environment
            2:55:21 PM: Using ruby version 2.7.1
            2:55:21 PM: Using PHP version 5.6
            2:55:21 PM: Started restoring cached node modules
            2:55:21 PM: Finished restoring cached node modules
            2:55:22 PM: Installing NPM modules using NPM version 6.14.4
            2:55:59 PM: > core-js@2.6.12 postinstall /opt/build/repo/node_modules/@babel/polyfill/node_modules/core-js
            2:55:59 PM: > node -e "try{require('./postinstall')}catch(e){}"
            2:55:59 PM: > core-js@3.8.1 postinstall /opt/build/repo/node_modules/core-js
            2:55:59 PM: > node -e "try{require('./postinstall')}catch(e){}"
            2:55:59 PM: > core-js-pure@3.8.1 postinstall /opt/build/repo/node_modules/core-js-pure
            2:55:59 PM: > node -e "try{require('./postinstall')}catch(e){}"
            2:56:02 PM: npm WARN pager-test@1.0.0 No repository field.
            2:56:02 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/watchpack/node_modules/fsevents):
            2:56:02 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
            2:56:02 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/react-dev-utils/node_modules/fsevents):
            2:56:02 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
            2:56:02 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/fsevents):
            2:56:02 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
            2:56:02 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.2.1 (node_modules/jest-haste-map/node_modules/fsevents):
            2:56:02 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.2.1: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
            2:56:02 PM: added 1696 packages from 1091 contributors and audited 1706 packages in 39.331s
            2:56:04 PM: 171 packages are looking for funding
            2:56:04 PM:   run `npm fund` for details
            2:56:04 PM: found 0 vulnerabilities
            2:56:04 PM: NPM modules installed
            2:56:04 PM: Started restoring cached go cache
            2:56:04 PM: Finished restoring cached go cache
            2:56:04 PM: go version go1.14.4 linux/amd64
            2:56:04 PM: go version go1.14.4 linux/amd64
            2:56:04 PM: Installing missing commands
            2:56:04 PM: Verify run directory
            2:56:06 PM: ​
            2:56:06 PM: ────────────────────────────────────────────────────────────────
            2:56:06 PM:   Netlify Build                                                 
            2:56:06 PM: ────────────────────────────────────────────────────────────────
            2:56:06 PM: ​
            2:56:06 PM: ❯ Version
            2:56:06 PM:   @netlify/build 8.0.0
            2:56:06 PM: ​
            2:56:06 PM: ❯ Flags
            2:56:06 PM:   deployId: 5fda6620f6d6dd00082b772f
            2:56:06 PM:   mode: buildbot
            2:56:06 PM: ​
            2:56:06 PM: ❯ Current directory
            2:56:06 PM:   /opt/build/repo
            2:56:06 PM: ​
            2:56:06 PM: ❯ Config file
            2:56:06 PM:   No config file was defined: using default values.
            2:56:06 PM: ​
            2:56:06 PM: ❯ Context
            2:56:06 PM:   production
            2:56:06 PM: ​
            2:56:06 PM: ────────────────────────────────────────────────────────────────
            2:56:06 PM:   1. Build command from Netlify app                             
            2:56:06 PM: ────────────────────────────────────────────────────────────────
            2:56:06 PM: ​
            2:56:06 PM: $ npm run build
            2:56:07 PM: > pager-test@1.0.0 build /opt/build/repo
            2:56:07 PM: > webpack -p
            2:56:11 PM: Hash: 151f0e45268df364d4f9
            2:56:11 PM: Version: webpack 4.44.2
            2:56:11 PM: Time: 3523ms
            2:56:11 PM: Built at: 12/16/2020 7:56:11 PM
            2:56:11 PM:  1 asset
            2:56:11 PM: Entrypoint main = bundle.js
            2:56:11 PM: [121] multi @babel/polyfill ./src/index.js 40 bytes {0} [built]
            2:56:11 PM:     + 307 hidden modules
            2:56:11 PM: ERROR in multi @babel/polyfill ./src/index.js
            2:56:11 PM: Module not found: Error: Can't resolve './src/index.js' in '/opt/build/repo' @ multi @babel/polyfill ./src/index.js main[1]
            2:56:11 PM: Child HtmlWebpackCompiler:
            2:56:11 PM:      1 asset
            2:56:11 PM:     Entrypoint HtmlWebpackPlugin_0 = __child-HtmlWebpackPlugin_0
            2:56:11 PM:     [0] ./node_modules/html-webpack-plugin/lib/loader.js!./src/index.html 298 bytes {0} [built]
            2:56:11 PM: npm ERR! code ELIFECYCLE
            2:56:11 PM: npm ERR! errno 2
            2:56:11 PM: npm ERR! pager-test@1.0.0 build: `webpack -p`
            2:56:11 PM: npm ERR! Exit status 2
            2:56:11 PM: npm ERR!
            2:56:11 PM: npm ERR! Failed at the pager-test@1.0.0 build script.
            2:56:11 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
            2:56:11 PM: npm ERR! A complete log of this run can be found in:
            2:56:11 PM: npm ERR!     /opt/buildhome/.npm/_logs/2020-12-16T19_56_11_926Z-debug.log
            2:56:11 PM: ​
            2:56:11 PM: ────────────────────────────────────────────────────────────────
            2:56:11 PM:   "build.command" failed                                        
            2:56:11 PM: ────────────────────────────────────────────────────────────────
            2:56:11 PM: ​
            2:56:11 PM:   Error message
            2:56:11 PM:   Command failed with exit code 2: npm run build
            2:56:11 PM: ​
            2:56:11 PM:   Error location
            2:56:11 PM:   In Build command from Netlify app:
            2:56:11 PM:   npm run build
            2:56:11 PM: ​
            2:56:11 PM:   Resolved config
            2:56:11 PM:   build:
            2:56:11 PM:     command: npm run build
            2:56:11 PM:     commandOrigin: ui
            2:56:12 PM: Caching artifacts
            2:56:12 PM: Started saving node modules
            2:56:12 PM: Finished saving node modules
            2:56:12 PM: Started saving build plugins
            2:56:12 PM: Finished saving build plugins
            2:56:12 PM: Started saving pip cache
            2:56:12 PM: Finished saving pip cache
            2:56:12 PM: Started saving emacs cask dependencies
            2:56:12 PM: Finished saving emacs cask dependencies
            2:56:12 PM: Started saving maven dependencies
            2:56:12 PM: Finished saving maven dependencies
            2:56:12 PM: Started saving boot dependencies
            2:56:12 PM: Finished saving boot dependencies
            2:56:12 PM: Started saving rust rustup cache
            2:56:12 PM: Finished saving rust rustup cache
            2:56:12 PM: Started saving rust cargo bin cache
            2:56:12 PM: Finished saving rust cargo bin cache
            2:56:12 PM: Started saving go dependencies
            2:56:12 PM: Finished saving go dependencies
            2:56:15 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
            2:56:15 PM: Failing build: Failed to build site
            2:56:15 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
            2:56:15 PM: Finished processing build request in 1m1.117047585s

Do you have any idea of it?

Hiya, sorry you are having trouble with your build.

This Support Guide contains a ton of useful debugging tips that can likely help you solve your problem :slight_smile:

We also recommend trying to search the forums with the build error you encountered - it’s likely your question was already asked by someone else!

If you are still having problems, please provide as much information as you can on what you have already tried, what your build settings are, your package.json, etc. Thanks!

This is my package.json

    {
      "name": "test",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "scripts": {
        "start": "webpack-dev-server -d --open",
        "build": "webpack -p",
        "storybook": "start-storybook -p 6006",
        "build-storybook": "build-storybook",
        "lint": "eslint ."
      },
      "keywords": [
        "pager"
      ],
      "author": "Hector Alcazar",
      "license": "ISC",
      "devDependencies": {
        "@babel/core": "^7.12.10",
        "@babel/preset-env": "^7.12.10",
        "@babel/preset-react": "^7.12.10",
        "@babel/polyfill": "^7.12.1",
        "@storybook/addon-actions": "^6.1.11",
        "@storybook/addon-essentials": "^6.1.11",
        "@storybook/addon-links": "^6.1.11",
        "@storybook/react": "^6.1.11",
        "babel-loader": "^8.2.2",
        "eslint": "^7.15.0",
        "eslint-plugin-react": "^7.21.5",
        "file-loader": "^6.2.0",
        "html-loader": "^1.3.0",
        "html-webpack-plugin": "^4.4.1",
        "prettier": "^2.1.2",
        "react-hot-loader": "^4.8.4",
        "webpack": "^4.30.0",
        "webpack-cli": "^3.3.0",
        "webpack-dev-server": "^3.3.1"
      },
      "dependencies": {
        "axios": "^0.21.0",
        "react": "^17.0.1",
        "react-dom": "^17.0.1",
        "react-router": "^5.2.0",
        "react-router-dom": "^5.2.0",
        "socket.io-client": "^2.3.0",
        "styled-components": "^5.2.1"
      },
      "resolutions": {
        "styled-components": "^5"
      }
    }

and this is the webpack configuration

    /* eslint-disable no-unused-vars */
    /* eslint-disable no-undef */
    const HtmlPlugin = require('html-webpack-plugin')
    const webpack = require('webpack')
    const path = require('path')

    module.exports = {
      output: {
        path: path.resolve(__dirname, 'build'),
        filename: 'bundle.js',
      },
      resolve: {
        extensions: ['.js', '.jsx'],
      },
      entry: ['@babel/polyfill', './src/index.js'],
      module: {
        rules: [
          {
            test: /\.(js|jsx)$/,
            exclude: /node_modules/,
            use: [
              {
                loader: 'babel-loader',
              },
            ],
          },
          {
            test: /\.html$/,
            use: [
              {
                loader: 'html-loader',
              },
            ],
          },
          {
            test: /\.(png|jpe?g|gif)$/i,
            use: [
              {
                loader: 'file-loader',
              },
            ],
          },
        ],
      },
      plugins: [
        new HtmlPlugin({
          filename: 'index.html',
          template: './src/index.html',
        }),
      ],
      devServer: {
        contentBase: path.join(__dirname, 'build'),
        compress: true,
        port: 8000,
        historyApiFallback: true,
      },
    }

and the build information

            2:55:12 PM: Build ready to start
            2:55:14 PM: build-image version: 53b83b6bede2920f236b25b6f5a95334320dc849
            2:55:14 PM: build-image tag: v3.6.0
            2:55:14 PM: buildbot version: dc0a2b81d00d8f0151c0b6d6eab301febfb9ab68
            2:55:14 PM: Fetching cached dependencies
            2:55:14 PM: Failed to fetch cache, continuing with build
            2:55:14 PM: Starting to prepare the repo for build
            2:55:14 PM: No cached dependencies found. Cloning fresh repo
            2:55:14 PM: git clone https://github.com/hiad/pager-test
            2:55:16 PM: Preparing Git Reference refs/heads/master
            2:55:17 PM: Starting build script
            2:55:18 PM: Installing dependencies
            2:55:18 PM: Python version set to 2.7
            2:55:19 PM: v12.18.0 is already installed.
            2:55:19 PM: Now using node v12.18.0 (npm v6.14.4)
            2:55:20 PM: Started restoring cached build plugins
            2:55:20 PM: Finished restoring cached build plugins
            2:55:20 PM: Attempting ruby version 2.7.1, read from environment
            2:55:21 PM: Using ruby version 2.7.1
            2:55:21 PM: Using PHP version 5.6
            2:55:21 PM: Started restoring cached node modules
            2:55:21 PM: Finished restoring cached node modules
            2:55:22 PM: Installing NPM modules using NPM version 6.14.4
            2:55:59 PM: > core-js@2.6.12 postinstall /opt/build/repo/node_modules/@babel/polyfill/node_modules/core-js
            2:55:59 PM: > node -e "try{require('./postinstall')}catch(e){}"
            2:55:59 PM: > core-js@3.8.1 postinstall /opt/build/repo/node_modules/core-js
            2:55:59 PM: > node -e "try{require('./postinstall')}catch(e){}"
            2:55:59 PM: > core-js-pure@3.8.1 postinstall /opt/build/repo/node_modules/core-js-pure
            2:55:59 PM: > node -e "try{require('./postinstall')}catch(e){}"
            2:56:02 PM: npm WARN pager-test@1.0.0 No repository field.
            2:56:02 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/watchpack/node_modules/fsevents):
            2:56:02 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
            2:56:02 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/react-dev-utils/node_modules/fsevents):
            2:56:02 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
            2:56:02 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/fsevents):
            2:56:02 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
            2:56:02 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.2.1 (node_modules/jest-haste-map/node_modules/fsevents):
            2:56:02 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.2.1: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
            2:56:02 PM: added 1696 packages from 1091 contributors and audited 1706 packages in 39.331s
            2:56:04 PM: 171 packages are looking for funding
            2:56:04 PM:   run `npm fund` for details
            2:56:04 PM: found 0 vulnerabilities
            2:56:04 PM: NPM modules installed
            2:56:04 PM: Started restoring cached go cache
            2:56:04 PM: Finished restoring cached go cache
            2:56:04 PM: go version go1.14.4 linux/amd64
            2:56:04 PM: go version go1.14.4 linux/amd64
            2:56:04 PM: Installing missing commands
            2:56:04 PM: Verify run directory
            2:56:06 PM: ​
            2:56:06 PM: ────────────────────────────────────────────────────────────────
            2:56:06 PM:   Netlify Build                                                 
            2:56:06 PM: ────────────────────────────────────────────────────────────────
            2:56:06 PM: ​
            2:56:06 PM: ❯ Version
            2:56:06 PM:   @netlify/build 8.0.0
            2:56:06 PM: ​
            2:56:06 PM: ❯ Flags
            2:56:06 PM:   deployId: 5fda6620f6d6dd00082b772f
            2:56:06 PM:   mode: buildbot
            2:56:06 PM: ​
            2:56:06 PM: ❯ Current directory
            2:56:06 PM:   /opt/build/repo
            2:56:06 PM: ​
            2:56:06 PM: ❯ Config file
            2:56:06 PM:   No config file was defined: using default values.
            2:56:06 PM: ​
            2:56:06 PM: ❯ Context
            2:56:06 PM:   production
            2:56:06 PM: ​
            2:56:06 PM: ────────────────────────────────────────────────────────────────
            2:56:06 PM:   1. Build command from Netlify app                             
            2:56:06 PM: ────────────────────────────────────────────────────────────────
            2:56:06 PM: ​
            2:56:06 PM: $ npm run build
            2:56:07 PM: > pager-test@1.0.0 build /opt/build/repo
            2:56:07 PM: > webpack -p
            2:56:11 PM: Hash: 151f0e45268df364d4f9
            2:56:11 PM: Version: webpack 4.44.2
            2:56:11 PM: Time: 3523ms
            2:56:11 PM: Built at: 12/16/2020 7:56:11 PM
            2:56:11 PM:  1 asset
            2:56:11 PM: Entrypoint main = bundle.js
            2:56:11 PM: [121] multi @babel/polyfill ./src/index.js 40 bytes {0} [built]
            2:56:11 PM:     + 307 hidden modules
            2:56:11 PM: ERROR in multi @babel/polyfill ./src/index.js
            2:56:11 PM: Module not found: Error: Can't resolve './src/index.js' in '/opt/build/repo' @ multi @babel/polyfill ./src/index.js main[1]
            2:56:11 PM: Child HtmlWebpackCompiler:
            2:56:11 PM:      1 asset
            2:56:11 PM:     Entrypoint HtmlWebpackPlugin_0 = __child-HtmlWebpackPlugin_0
            2:56:11 PM:     [0] ./node_modules/html-webpack-plugin/lib/loader.js!./src/index.html 298 bytes {0} [built]
            2:56:11 PM: npm ERR! code ELIFECYCLE
            2:56:11 PM: npm ERR! errno 2
            2:56:11 PM: npm ERR! pager-test@1.0.0 build: `webpack -p`
            2:56:11 PM: npm ERR! Exit status 2
            2:56:11 PM: npm ERR!
            2:56:11 PM: npm ERR! Failed at the pager-test@1.0.0 build script.
            2:56:11 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
            2:56:11 PM: npm ERR! A complete log of this run can be found in:
            2:56:11 PM: npm ERR!     /opt/buildhome/.npm/_logs/2020-12-16T19_56_11_926Z-debug.log
            2:56:11 PM: ​
            2:56:11 PM: ────────────────────────────────────────────────────────────────
            2:56:11 PM:   "build.command" failed                                        
            2:56:11 PM: ────────────────────────────────────────────────────────────────
            2:56:11 PM: ​
            2:56:11 PM:   Error message
            2:56:11 PM:   Command failed with exit code 2: npm run build
            2:56:11 PM: ​
            2:56:11 PM:   Error location
            2:56:11 PM:   In Build command from Netlify app:
            2:56:11 PM:   npm run build
            2:56:11 PM: ​
            2:56:11 PM:   Resolved config
            2:56:11 PM:   build:
            2:56:11 PM:     command: npm run build
            2:56:11 PM:     commandOrigin: ui
            2:56:12 PM: Caching artifacts
            2:56:12 PM: Started saving node modules
            2:56:12 PM: Finished saving node modules
            2:56:12 PM: Started saving build plugins
            2:56:12 PM: Finished saving build plugins
            2:56:12 PM: Started saving pip cache
            2:56:12 PM: Finished saving pip cache
            2:56:12 PM: Started saving emacs cask dependencies
            2:56:12 PM: Finished saving emacs cask dependencies
            2:56:12 PM: Started saving maven dependencies
            2:56:12 PM: Finished saving maven dependencies
            2:56:12 PM: Started saving boot dependencies
            2:56:12 PM: Finished saving boot dependencies
            2:56:12 PM: Started saving rust rustup cache
            2:56:12 PM: Finished saving rust rustup cache
            2:56:12 PM: Started saving rust cargo bin cache
            2:56:12 PM: Finished saving rust cargo bin cache
            2:56:12 PM: Started saving go dependencies
            2:56:12 PM: Finished saving go dependencies
            2:56:15 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
            2:56:15 PM: Failing build: Failed to build site
            2:56:15 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
            2:56:15 PM: Finished processing build request in 1m1.117047585s

it seems like babel-polyfill isn’t being found correctly.

The reason for this is because it is installed as a development dependency, not a production one, so it is not installed when you trigger a production build, but it needs to be a production dependency to work correctly.

From the polyfill package site:

Because this is a polyfill (which will run before your source code), we need it to be a dependency , not a devDependency