1

UPDATE: I fixed the issue. Look in answers.

Goal: Set up Babel.

Issue: I run into an error when I use webpack to create a bundle.js file using the command: npm run dev. screenshot 1 screenshot 2

./src/js/index.js

import num from "./test";
const x = 45;
console.log(`I imported ${num} from test.js - ${x}`);

webpack.config.js:

const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");

module.exports = {
    entry: ["babel-polyfill", "./src/js/index.js"],
    output: {
        path: path.resolve(__dirname, "dist"),
    filename: "js/bundle.js"
    },
    devServer: {
    contentBase: "./dist"
    },
    plugins: [
    new HtmlWebpackPlugin({
        filename: "index.html",
        template: "./src/index.html"
    })
    ],
    module: {
    rules: [ 
        {
        test: /\.js$/, 
        exclude: /node_modules/, 
        use: { 
            loader: "babel-loader"
                }
        }
        ]
    }
};
2
  • You're missing a module: npm i -D @babel/core Commented Aug 30, 2018 at 19:48
  • I have the package installed already. It shows up in my package.json file. Commented Aug 30, 2018 at 19:50

2 Answers 2

1

I fixed the error. Turns out I needed to install new Babel packages.

npm install --save-dev @babel/core @babel/preset-env
npm install --save @babel/polyfill

Replace entry in webpack.config.js with:

entry: ["@babel/polyfill", "./src/js/index.js"],

Replace presets in .babelrc with:

{
  "presets": ["@babel/env"]
}
Sign up to request clarification or add additional context in comments.

Comments

0

Looks like you're missing babel-core

I think running:

npm install --save-dev babel-core

Should fix it

9 Comments

I have the package installed already. It shows up in my package.json file.
Just saw your other comment about it being in package.json. Try deleting node_modules, and then npm install again
Or, to confirm it is indeed installed, open the node_modules folder, and see if you can see the babel-core folder
Babel-core is in node_modules.
what's in the /.test file?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.