Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find module '@babel/plugin-transform-runtime' from

I m getting the error " Cannot find module '@babel/plugin-transform-runtime' from ...". I have tried every solution on the internet but nothing really works. How can i solve it ? Any suggestion would be greatly appriciated.

babelrc

{
    "presets": [
        "@babel/preset-react",
        "@babel/preset-env"
    ],
    "plugins": [
        ["transform-runtime", {
            "helpers": false, // defaults to true
            "polyfill": false, // defaults to true
            "regenerator": true, // defaults to true
            "moduleName": "babel-runtime" // defaults to "babel-runtime"
        }]
    ]}

webpack

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

module.exports = {
    mode: 'development',
    resolve: {
        extensions: ['.js', '.jsx', '.css']
    },
    module: {
        rules: [
            {
                test: /\.jsx?$/,
                loader: 'babel-loader'
            },
            {
                test: /\.css$/,
                use: [ 'style-loader', 'css-loader' ]
            }
        ]
    },
    resolve: {
        extensions: ['.js', '.jsx', '.css'],
        alias: {
            '@': path.resolve(__dirname, 'src/'),
        }
    },

    plugins: [new HtmlWebpackPlugin({
        template: './src/index.html'
    })],
    devServer: {
        historyApiFallback: true
    },
    externals: {
        // global app config object
        config: JSON.stringify({
            apiUrl: 'https://obidentity-develop.azurewebsites.net/connect/token'
        })
    }
}
like image 905
Tolga Tamer Avatar asked Feb 28 '20 20:02

Tolga Tamer


People also ask

What does Babel transform runtime do?

A plugin that enables the re-use of Babel's injected helper code to save on codesize.

Can not find Babel core?

To solve the error "Cannot find module '@babel/core'", make sure to install the @babe/core package by opening your terminal in your project's root directory and running the following command: npm i -D @babel/core and restart your IDE and development server.

Can't resolve '@ Babel runtime corejs3 helpers extends?

To solve the error "Module not found: Error: Can't resolve '@babel/runtime/helpers'", make sure to install the @babel/runtime package by opening your terminal in your project's root directory and running the command npm install @babel/runtime and restart your development server.


2 Answers

try to add

"plugins": ["@babel/plugin-transform-runtime"]

in .babelrc

like image 98
lovelyPrackets Avatar answered Sep 20 '22 23:09

lovelyPrackets


I met this problem when I was running 2 different versions of node:

  • terminal 1: node 14, npm install
  • terminal 2: node 16, npm run dev

so the dependencies are mess up, and something very strange happens.

solution:

  1. remove node_modules folder
  2. open 1 terminal, npm install and npm run dev
like image 38
Siwei Avatar answered Sep 20 '22 23:09

Siwei