I have a carousel file in which I want to get index.js and build block.build.js, so my webpack.config.js is:
var config = {
entry: './index.js',
output: {
path: __dirname,
filename: 'block.build.js',
},
devServer: {
contentBase: './Carousel'
},
module : {
rules : [
{
test: /.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
presets: ['react', 'es2015'],
plugins: ['transform-class-properties']
}
}
]
}
};
module.exports = config;
The package.json which I use is below:
{
"name": "carousel",
"version": "1.0.0",
"description": "",
"main": "webpack.config.js",
"dependencies": {
"#babel/core": "^7.0.0-beta.40",
"babel-cli": "^6.26.0",
"babel-loader": "^8.0.0-beta.0",
"babel-plugin-lodash": "^3.3.2",
"babel-plugin-react-transform": "^3.0.0",
"babel-preset-react": "^6.24.1",
"cross-env": "^5.1.3",
"lodash": "^4.17.5",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-swipeable": "^4.2.0",
"styled-components": "^3.2.1"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"watch": "webpack --watch",
"start": "webpack-dev-server --open",
"build": "webpack"
},
"devDependencies": {
"webpack": "^4.1.1",
"webpack-cli": "^2.0.10",
"webpack-dev-server": "^3.1.0"
},
"author": "brad traversy",
"license": "ISC"
}
… but I get this error message:
ERROR in ./index.js
Module build failed: Error: Plugin/Preset files are not allowed to export objects, only functions.
Does anyone know how to solve this?
You're using a combination of Babel 6 and Babel 7. There is no guarantee of compatibility across versions:
"#babel/core": "^7.0.0-beta.40",
"babel-cli": "^6.26.0",
"babel-loader": "^8.0.0-beta.0",
"babel-plugin-lodash": "^3.3.2",
"babel-plugin-react-transform": "^3.0.0",
"babel-preset-react": "^6.24.1",
should be
"#babel/core": "^7.0.0-beta.40",
"#babel/cli": "^7.0.0-beta.40",
"babel-loader": "^8.0.0-beta.0",
"babel-plugin-lodash": "^3.3.2",
"babel-plugin-react-transform": "^3.0.0",
"#babel/preset-react": "^7.0.0-beta.40",
and
query: {
presets: ['react', 'es2015'],
plugins: ['transform-class-properties']
}
would be
query: {
presets: ['#babel/react', '#babel/es2015'],
plugins: ['#babel/proposal-class-properties']
}
I'm also confused because you didn't mention #babel/proposal-class-properties in your package.json, but assuming it is in there it should also be updated.
It happened to me and a simple solution for me was to uninstall babel-loader#8^ and #babel/core:
npm uninstall --save babel-loader
npm uninstall --save #babel/core
… and then to install version 7 babel-loader:
npm install --save-dev babel-loader#^7
Got the same issue in my webpack/react project - it seems that there was an issue with the .babelrc file.
I updated it as seen below and it did the trick:
{
"presets": [
"#babel/preset-env",
"#babel/preset-react"
],
"plugins": [
"transform-class-properties",
"transform-object-rest-spread"
]
}
Also from babel-loader v8, they have changed a little bit:
webpack 4.x | babel-loader 8.x | babel 7.x
npm install -D babel-loader #babel/core #babel/preset-env webpack
webpack 4.x | babel-loader 7.x | babel 6.x
npm install -D babel-loader#7 babel-core babel-preset-env webpack
(same thing for #babel/preset-react instead of babel-preset-react).
There are upgrades in babel 7 from version 6 refer to https://babeljs.io/docs/en/v7-migration. To solve the current problem/error
Install
npm install --save-dev #babel/preset-react
npm install --save-dev #babel/preset-env
then in .babelrc the dependency for presets should look like
{
"presets":["#babel/preset-env", "#babel/preset-react"],
"plugins": [
"react-hot-loader/babel", "transform-object-rest-spread"]
}
this worked for me:
npm uninstall --save babel-loader
npm uninstall --save #babel/core
npm install --save-dev babel-loader#^7
and in babelrc:
"presets" : ["es2015", "react"]
This solution worked for me:
npm install babel-loader babel-preset-react
then in .babelrc
{
"presets": [
"#babel/preset-env", "#babel/preset-react"
]
}
then run npm run start, webpack will generate the dist directory.
I had "stage-1" within my presets in .babelrc, so I removed that and the error went away
in webpack.config.js file add
module: {
rules: [{
loader: 'babel-loader',
test: /\.(js|jsx)$/,
exclude: /(node_modules|bower_components)/,
options: { presets: ['#babel/env','#babel/preset-react'] }
},
]
}
and create a file named .babelrc
{ "presets": [
"#babel/preset-env",
"#babel/preset-react"
]
}
and in package.json must install these dependencies and devDependencies
"dependencies": {
"#babel/preset-env": "^7.16.0",
"#babel/preset-react": "^7.16.0",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"validator": "^13.7.0",
"webpack": "^5.62.1"
},
"devDependencies": {
"#babel/core": "^7.16.0",
"#types/react": "^17.0.34",
"#types/react-dom": "^17.0.11",
"babel-loader": "^8.2.3",
"nodemon": "^2.0.14",
"webpack-cli": "^4.9.1"
}
first, remove installed packages
if yarn use
yarn remove babel-core babel-loader babel-preset-env babel-preset-react
if npm use
npm uninstall babel-core babel-loader babel-preset-env babel-preset-react
Then install packages
install using yarn
yarn add -D #babel/core babel-loader #babel/preset-env #babel/preset-react
install using npm
npm add -D #babel/core babel-loader #babel/preset-env #babel/preset-react
Replace your .babelrc file following code this fix my issue
{
"presets": ["module:metro-react-native-babel-preset"]
}
The solution that worked for me using Yarn was:
yarn add babel-loader babel-preset-react #babel/preset-env #babel/preset-react -D
then in .babelrc.json or only .babelrc
{
"presets": [
"#babel/preset-env", "#babel/preset-react"
]
}
then run webpack or yarn webpack, it'll generate the dist on the project root directory.
Clearly seems like you're facing issues due to the non-compatibility of babel-preset-react and babel-preset-env modules. These modules are now obsolete so you may need to install their latest alternatives. #babel/core seems to be fine.
Here's what you need to do:
Remove all the old babel-related modules. Although it's not necessary to remove all of them but I would suggest you start with a clean slate.
yarn remove babel-preset-react babel-preset-env
Or if you're using npm then enter the following code in the terminal:
npm uninstall babel - preset - react babel - preset - env
Once the old modules are removed, install the new ones. I'm showing codes for both yarn and npm
yarn add #babel/core #babel/preset-react #babel/preset/env --save
npm i #babel/core #babel/preset-react #babel/preset/env --save
Note that even if you already have #babel/core module installed, reinstall it as it helped me run my code for whatever reasons.
After that, as a final step, go ahead and edit your .babelrc file with this code:
{
"presets": [
"#babel/preset-env",
"#babel/preset-react"
]
}
Related
So I have been trying to setup React Js environment. I am facing the babel dependencies error. I know this problem is very common and there are tons of answers available but none of them have worked for me so far.
I have searched through the internet to solve it but it still shows the same error.
This is the error I am getting:
ERROR in ./main.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Cannot find module 'babel-preset-es2015' from 'D:\my-app'
at Function.module.exports [as sync] (D:\my-app\node_modules\resolve\lib\sync.js:58:15)
at resolveStandardizedName (D:\my-app\node_modules\#babel\core\lib\config\files\plugins.js:101:31)
at resolvePreset (D:\my-app\node_modules\#babel\core\lib\config\files\plugins.js:58:10)
at loadPreset (D:\my-app\node_modules\#babel\core\lib\config\files\plugins.js:77:20)
at createDescriptor (D:\my-app\node_modules\#babel\core\lib\config\config-descriptors.js:154:9)
at items.map (D:\my-app\node_modules\#babel\core\lib\config\config-descriptors.js:109:50)
at Array.map (<anonymous>)
at createDescriptors (D:\my-app\node_modules\#babel\core\lib\config\config-descriptors.js:109:29)
at createPresetDescriptors (D:\my-app\node_modules\#babel\core\lib\config\config-descriptors.js:101:10)
at passPerPreset (D:\my-app\node_modules\#babel\core\lib\config\config-descriptors.js:58:96)
Child html-webpack-plugin for "index.html":
1 asset
Entrypoint undefined = index.html
[./node_modules/html-webpack-plugin/lib/loader.js!./index.html] 448 bytes {0} [built]
[./node_modules/lodash/lodash.js] 527 KiB {0} [built]
[./node_modules/webpack/buildin/global.js] (webpack)/buildin/global.js 472 bytes {0} [built]
[./node_modules/webpac
This is my .babelrc
{
"presets": ["es2015"]
}
webpack.config.js
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './main.js',
output: {
path: path.join(__dirname, '/bundle'),
filename: 'index_bundle.js'
},
devServer: {
inline: true,
port: 8080
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['es2015', 'react']
}
}
]
},
plugins:[
new HtmlWebpackPlugin({
template: './index.html'
})
]
}
package.json
{
"name": "my-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --mode development --open --hot",
"build": "webpack --mode production"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"babel-core": "^6.26.3",
"babel-preset-env": "^1.7.0",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"webpack-cli": "^3.3.2",
"webpack-dev-server": "^3.3.1"
},
"devDependencies": {
"#babel/core": "^7.4.4",
"#babel/preset-env": "^7.4.4",
"#babel/preset-es2015": "^7.0.0-beta.53",
"babel-loader": "^8.0.6",
"html-webpack-plugin": "^3.2.0",
"webpack": "^4.31.0"
}
}
babel-loader#8.x uses Babel 7.x, which is #babel/core#^7.0.0, and more importantly in your case #babel/preset-env#7 replaces babel-preset-env#^1.7.0.
You'll need to make sure to do
npm install #babel/core #babel/preset-env
and update your Babel config to use #babel/preset-env instead of babel-preset-env with something like
"presets": [
"#babel/preset-env"
]
Note: For others coming across this, the issue may also be that you're using plugins/preset from Babel 6 on Babel 7. This may be hard to notice if you're using a third-party Babel preset since the versions of the presets may not match the version of Babel itself.
For NPM, run
npm install -D babel-loader #babel/core #babel/preset-env webpack
FOR YARN, run
yarn add --dev babel-loader #babel/core #babel/preset-env webpack
Late but might be helpful.
Downgrade the version of #babel-loader to version 7.
It worked for me when i encountered same problem
If you noticed this after installing a package like web3.
Kill the server and try to rebuild hope it helps
I've running npm run dev command to run my react app. BUT then it pops up this Error: Cannot find module 'webpack/bin/config-yargs'. I've googled this error. Many people who solve this error tell me to install webpack and webpack-cli. Therefore, I went to install webpack and webpack-cli. However, the error still pops up. PLEASE HELP!
I've tried several solution, such as this
Cannot find module 'webpack/bin/config-yargs'
and this
How to solve 'Cannot find module 'webpack-cli/bin/config-yargs' error in reactjs?
NOW I've installed webpack and webpack-cli.
My cmd
C:\Users\ASUS\Desktop\truffle-webpack-ipfs-bootstrap-master\truffle-webpack-ipfs-bootstrap-master>npm run dev
> truffle-init-webpack#0.0.2 dev C:\Users\ASUS\Desktop\truffle-webpack-ipfs-bootstrap-master\truffle-webpack-ipfs-bootstrap-master
> webpack-dev-server
internal/modules/cjs/loader.js:613
throw err;
^
Error: Cannot find module 'webpack/bin/config-yargs'
Require stack:
- C:\Users\ASUS\Desktop\truffle-webpack-ipfs-bootstrap-master\truffle-webpack-ipfs-bootstrap-master\node_modules\webpack-dev-server\bin\webpack-dev-server.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:610:15)
at Function.Module._load (internal/modules/cjs/loader.js:526:27)
at Module.require (internal/modules/cjs/loader.js:666:19)
at require (internal/modules/cjs/helpers.js:16:16)
at Object.<anonymous> (C:\Users\ASUS\Desktop\truffle-webpack-ipfs-bootstrap-master\truffle-webpack-ipfs-bootstrap-master\node_modules\webpack-dev-server\bin\webpack-dev-server.js:54:1)
at Module._compile (internal/modules/cjs/loader.js:759:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
at Module.load (internal/modules/cjs/loader.js:628:32)
at Function.Module._load (internal/modules/cjs/loader.js:555:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:824:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! truffle-init-webpack#0.0.2 dev: `webpack-dev-server`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the truffle-init-webpack#0.0.2 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\ASUS\AppData\Roaming\npm-cache\_logs\2019-08-30T09_10_59_739Z-debug.log
My package.json
{
"name": "truffle-init-webpack",
"version": "0.0.2",
"description": "Frontend example using truffle v3",
"scripts": {
"lint": "eslint ./",
"build": "webpack",
"dev": "webpack-dev-server"
},
"author": "Douglas von Kohorn",
"license": "MIT",
"devDependencies": {
"babel-cli": "^6.22.2",
"babel-core": "^6.26.3",
"babel-eslint": "^6.1.2",
"babel-loader": "^6.2.10",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.22.0",
"babel-register": "^6.22.0",
"copy-webpack-plugin": "^4.6.0",
"css-loader": "^3.2.0",
"eslint": "^3.14.0",
"eslint-config-standard": "^6.0.0",
"eslint-plugin-babel": "^4.0.0",
"eslint-plugin-mocha": "^4.8.0",
"eslint-plugin-promise": "^3.8.0",
"eslint-plugin-standard": "^2.0.0",
"html-webpack-plugin": "^2.28.0",
"json-loader": "^0.5.4",
"style-loader": "^0.13.1",
"truffle-contract": "^1.1.11",
"web3": "^0.20.7",
"webpack": "^4.0.0",
"webpack-cli": "^3.3.7",
"webpack-dev-server": "^2.11.5"
},
"dependencies": {
"ajv": "^5.5.2",
"boostrap": "^2.0.0",
"bootstrap": "^4.3.1",
"ipfs-api": "^19.0.0",
"jquery": "^3.4.1",
"node-sass": "^4.8.3",
"popper.js": "^1.15.0",
"postcss-loader": "^2.1.6",
"precss": "^3.1.2",
"sass-loader": "^6.0.7"
}
}
I had the same problem and it was because the webpack version was not stable
I used the lower version and the problem was solved
npm install webpack#4.32.2 --save-dev
npm install webpack-cli#3.3.2 --save-dev
npm install webpack-dev-server#3.5.1 --save-dev
In your package.json file just change "dev": "webpack-dev-server" to "dev": "webpack serve"
If you have the error for the issues described here: https://github.com/webpack/webpack-dev-server/issues/2029
I wrote a python script to fix the problem until it's patched.
You can just add the command to your package.json script after adding the file to your project (assuming you have python installed).
https://github.com/bigbizze/FixWebPackError-Cannot-find-module-webpack-cli-bin-config-yargs
Try the following. Its worked for me
"scripts": {
"lint": "eslint ./",
"build": "webpack",
"dev": "webpack serve"
},
I had the same problem, try npm install --save-dev webpack webpack-cli webpack-dev-server webpack-merge
I think it's related to webpack version only. Can you please update the webpack, webpack-cli and webpack-dev-server with latest version and check it.
Hope this will work for you!
in package.json
use "dev":"webpack serve" instead of "webpack-dev-server"
Don't play with the webpack module for a while you are learning because it is tricky to do this stuff.
I have the same problem that you listed before
// change your mode to development in package.json
// make everything in devDependencies
{
"name": "timer",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "webpack",
"start": "webpack-dev-server"
},
"babel": {
"presets": [
"#babel/preset-env",
"#babel/preset-react"
]
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"devDependencies": {
...
}
}
In your webpack.config
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
entry: './app/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'index_bundle.js'
},
module: {
rules: [
{ test: /\.(js)$/, use: 'babel-loader' },
{ test: /\.css$/, use: [ 'style-loader', 'css-loader' ]}
]
},
mode: 'development',
plugins: [
new HtmlWebpackPlugin({
template: 'app/index.html'
})
]
}
This may work for you.
I'm very new to React.js. I installed Laravel 5.7 and swapped Vue.js scaffolding with React by running this command:
php artisan preset react
Now the problem is, I cannot assign anything to the state inside a component.
For example if I do the following inside the component:
state = { foo: false };
I got the error:
ERROR in ./resources/js/components/Root.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: D:\xampp\htdocs\smart-school-v0.1\resources\js\components\Root.js: Support for the experimental syntax 'classProperties' isn't currently enabled (8:11):
I installed:
#babel/plugin-proposal-class-properties
and updated .babelrc (Babel configuration file) like this:
{
"presets": [
"#babel/preset-env",
"#babel/preset-react"
],
"plugins": [
"#babel/plugin-proposal-class-properties"
]
}
I followed this but no luck.
Package.json
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"#babel/plugin-proposal-class-properties": "^7.2.3",
"#babel/preset-env": "^7.2.3",
"#babel/preset-react": "^7.0.0",
"axios": "^0.18",
"babel-preset-react": "^6.23.0",
"bootstrap": "^4.0.0",
"cross-env": "^5.1",
"jquery": "^3.2",
"laravel-mix": "^4.0.13",
"lodash": "^4.17.5",
"popper.js": "^1.12",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"resolve-url-loader": "^2.3.1",
"sass": "^1.15.3",
"sass-loader": "^7.1.0"
},
"dependencies": {
"react-router-dom": "^4.3.1"
}
}
.babelrc
{
"presets": [
"#babel/preset-env",
"#babel/preset-react"
],
"plugins": [
"#babel/plugin-proposal-class-properties"
]
}
Root.js Component
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
export default class Root extends Component {
state = { foo: false };
render() {
return (
<p>Loaded</p>
);
}
}
if (document.getElementById('app')) {
ReactDOM.render(<Root />, document.getElementById('app'));
}
It is not working as expected and I'm keep getting this error:
Syntax Error: SyntaxError: D:\xampp\htdocs\smart-school-v0.1\resources\js\components\Root.js: Support for the experimental syntax 'classProperties' isn't currently enabled (19:11):
17 |
18 |
> 19 | state = { foo: false };
| ^
20 |
21 | render() {
22 |
Add #babel/plugin-proposal-class-properties (https://git.io/vb4SL) to the 'plugins' section of your Babel config to enable transformation.
# ./resources/js/app.js 14:0-28
# multi ./resources/js/app.js ./resources/sass/app.scss
Asset Size Chunks
Chunk Names
/css/app.css 0 bytes /js/app [emitted] /js/app
/js/app.js 593 KiB /js/app [emitted] /js/app
ERROR in ./resources/js/components/Root.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: D:\xampp\htdocs\smart-school-v0.1\resources\js\components\Root.js: Support for the experimental syntax 'classProperties' isn't currently enabled (19:11):
Please help me out.
Thanks in advance.
Cretae .babelrc file in root folder.
Write in .babelrc:
{ "plugins": ["#babel/plugin-proposal-class-properties"] }
Run npm install --save-dev #babel/plugin-proposal-class-properties
Run npm run dev
Hope it will help you.
I just tested on Laravel Framework 5.7.19 and the following steps work:
Make sure your .babelrc file is in the root folder of your application, and add the following code:
{
"plugins": ["#babel/plugin-proposal-class-properties"]
}
Run npm install --save-dev #babel/plugin-proposal-class-properties.
Run npm run watch.
Simple Add this to your
package.json
"babel": {
"presets": [
"#babel/preset-env",
"#babel/preset-react"
],
"plugins": [
"#babel/plugin-proposal-class-properties"
]
}
You can simply
create .babelrc file and paste this code in your .babelrc file
{ "plugins": ["#babel/plugin-proposal-class-properties"] }
and now run npm install --save-dev #babel/plugin-proposal-class-proper
and finally run npm run watch
done
Just add these lines to your Package.json file:
"babel": {
"presets": [
"#babel/preset-env",
"#babel/preset-react"
],
"plugins": [
"#babel/plugin-proposal-class-properties"
]
}
I apologize if this has been asked before, I can't find it. I'm a beginner and I've been trying to set up webpack so I can start learning react. After following a tutorial on youtube, I've installed react with
npm install --save react react-dom
And also tried enabling ES6 and JSX with
npm install --save-dev babel-cli babel-preset-react
npm install babel-preset-env --save-dev
And while trying to run dev, I get these errors:
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! webpack-starter#1.0.0 dev: `webpack-dev-server`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the webpack-starter#1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
This is my webpack.config.js
var HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
var path = require("path");
module.exports = {
entry: './src/app.js',
output: {
path: path.resolve(__dirname, "dist"),
filename: 'app.bundle.js'
},
devServer: {
contentBase: path.join(__dirname, "dist"),
compress: true,
stats: "errors-only",
open: true,
openPage: ''
},
module: {
rules: [
{test: /\.scss$/, use: ExtractTextPlugin.extract({fallback: 'style-loader', use: ['css-loader', 'sass-loader']})},
]
},
plugins: [
new HtmlWebpackPlugin({
title: 'Project Demo',
minify: {
collapseWhitespace: false // For minifying HTML to save on space
},
hash: false, // Name of app.bundle.js is changing to see if we're uploading the latest files
template: './src/index.html', // Load a custom template (ejs by default see the FAQ for details)
}),
new ExtractTextPlugin("app.css"),
]
}
I've also made .babelrc inside src folder. It contains this:
{
"presets": ["es2015", "react"]
}
While installing all those above, the only warning I got was
npm WARN webpack-dev-server#2.5.0 requires a peer of webpack#^2.2.0
but none is installed. You must install peer dependencies yourself.
But if I understand correctly, it's not an error, just a warning. Meaning, everything should still work. Am I wrong?
Can someone please let me know what is happening? How can I fix this?
Thank you!
EDIT: Here is my package.json too:
{
"name": "webpack-starter",
"version": "1.0.0",
"description": "Webpack project starter",
"main": "index.js",
"scripts": {
"dev": "webpack-dev-server",
"prod": "webpack -p"
},
"author": "Name",
"license": "ISC",
"devDependencies": {
"babel": "^6.23.0",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-es2015-webpack": "^6.4.3",
"babel-preset-react": "^6.24.1",
"css-loader": "^0.28.7",
"extract-text-webpack-plugin": "^3.0.1",
"html-webpack-plugin": "^2.30.1",
"node-sass": "^4.5.3",
"react": "^16.1.1",
"react-dom": "^16.1.1",
"sass-loader": "^6.0.6",
"style-loader": "^0.19.0",
"webpack": "^3.8.1",
"webpack-dev-server": "^2.9.4"
},
"dependencies": {}
}
webpack-dev-server 2.5.0 isn't compatible with webpack v3 or above and hence you need to upgrade your webpack-dev-server to 2.5.1 which fixed this issue. See this github issue
You can do this by changing the version in package.json to 2.5.1 and running npm install
or
You can uninstall and reinstall it
npm uninstall webpack-dev-server --save-dev
npm install webpack-dev-server --save-dev
I have a React project using Webpack and Babel. When I created it on an office computer, the Webpack ran fine. When I cloned the project onto my personal computer, it gave the following error:
ERROR in ./react_minesweeper.jsx
Module build failed: Error: Couldn't find preset "es2015" relative to directory "/Users/louisstephancruz/Desktop"
at /Users/louisstephancruz/Desktop/w6d5/minesweeper/node_modules/babel-core/lib/transformation/file/options/option-manager.js:298:19
at Array.map (native)
at OptionManager.resolvePresets (/Users/louisstephancruz/Desktop/w6d5/minesweeper/node_modules/babel-core/lib/transformation/file/options/option-manager.js:269:20)
Here's my webpack.config.js:
module.exports = {
entry: './react_minesweeper.jsx',
output: {
path: './',
filename: 'bundle.js',
},
module: {
loaders: [
{
test: [/\.jsx?$/, /\.js?$/],
exclude: /(node_modules)/,
loader: 'babel',
query: {
presets: ['es2015', 'react']
}
}
]
},
devtool: 'source-map',
resolve: {
extensions: ['', '.js', '.jsx' ]
}
};
Here's my package.json:
{
"name": "minesweeper",
"version": "1.0.0",
"description": "",
"main": "webpack.config.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack-dev-server --inline"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"babel": "^6.5.2",
"babel-core": "^6.17.0",
"babel-loader": "^6.2.5",
"babel-preset-es2015": "^6.16.0",
"babel-preset-react": "^6.16.0",
"webpack": "^1.13.2",
"webpack-dev-server": "^1.16.2"
},
"dependencies": {
"react": "^15.3.2",
"react-dom": "^15.3.2"
}
}
My version of node is: v5.6.0
My version of npm is: 3.6.0
npm i or npm install
should install all the packages in your package.json dependencies and dev dependencies (so long as your NODE_ENV environment variable does not equal production).
To check if you have a particular package installed you may do:
npm ls babel-preset-es2015
If for some reason your NODE_ENV is production and you would like to install dev dependencies you can use:
npm install --only=dev
Conversely, the following may be used on production machines that are dealing with already built code and do not need access to any development dependencies:
npm install --only=prod
I'd recommend creating a .babelrc in the root of your repo with the following content:
{ "presets": [ "es2015", "react" ] }
For the webpack config you may want to specify some other options:
{ context: __dirname
, resolve: { root: __dirname, extensions: [ '.js', '.jsx', '.json' ] }
}
in addition to the rest of your configuration, this tells webpack where the root directory of the bundling should take place from and what file extensions to treat as modules (which extensions you can omit in require / import statements).
I'd recommend checking out webpack's resolve.extensions for more information on that bit.
npm install babel-preset-es2015
does that help?
I resolved this issue when I removed .babelrc (hidden) file from "/Users/username" directory.
For me, I had to install the package globally.
npm install babel-preset-es2015 --save -g
npm install babel-preset-es2015 babel-preset-stage-2 --save
It's worked for me.