Following is the webpack.config.js file for my React app
module.exports = {
entry: 'index.js',
output: {
filename: 'bundle.js',
path: '/.'
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
query: {
presets: ['react']
}
}
]
}
};
and the error I am getting on execution is following:
npm ERR! code ELIFECYCLE
npm ERR! errno 4294967295
npm ERR! loginpoc#1.0.0 start: `webpack-dev-server --hot`
npm ERR! Exit status 4294967295
npm ERR!
npm ERR! Failed at the loginpoc#1.0.0 start script 'webpack-dev-server --hot'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the loginpoc package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! webpack-dev-server --hot
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs loginpoc
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls loginpoc
npm ERR! There is likely additional logging output above
my package.json is as follows
{
"name": "loginpoc",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --hot"
},
"author": "",
"license": "ISC",
"dependencies": {
"react": "^15.5.3",
"react-dom": "^15.5.3",
"webpack": "^2.3.3",
"webpack-dev-server": "^2.4.2"
}
}
kindly let me know what do you suggest where am I going wrong?
There are some changes needed to make your config work. Since the error you posted is just the noise from npm, the actual error is above all that, I'll show you the actual errors you get and how you can fix them.
ERROR in Entry module not found: Error: Can't resolve 'index.js'
An entry point for webpack is just like a regular import. This is not a relative path, therefore webpack resolves it as a module, it looks for a module index.js in node_modules. Presumably you want it to be:
entry: './index.js'
After fixing that you'll run into the following error:
ERROR in Entry module not found: Error: Can't resolve 'babel-loader'
You're using babel-loader in your webpack config, but you don't have it installed. Well you might have it installed, but it's not in your package.json so you either have it globally installed or you forgot to add --save or --save-dev respectively on npm install. Either way it should be listed as a dependency in your package.json so it also works on another machine by simply running npm install.
The dependencies related to babel-loader would produce the same error, so you can install all of them at once:
npm install --save-dev babel-loader babel-core babel-preset-react
And finally the last error you might encounter is:
Error: EACCES: permission denied, open '/bundle.js'
You'll not get this, if you're executing it as root or your user is allowed to write to / (the root of your file system). Anyway you don't want that, because the generated bundle should be somewhere in the directory of the project, otherwise multiple projects would end up overwriting the same bundle. You've also set the output.path to /. so maybe it was a typo and you meant ./. That wouldn't be allowed, because output.path needs to be an absolute path. You can use path.resolve for that.
output: {
filename: 'bundle.js',
path: path.resolve(__dirname)
}
You generally want output.path to be a directory inside your project, e.g. dist so you can easily separate the output from your regular files.
Here is the full config with all the changes mentioned above:
const path = require('path');
module.exports = {
entry: './index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
query: {
presets: ['react']
}
}
]
}
};
Try using this as your configuration.
var path = require('path'),
module.exports = {
entry: 'index.js',
output: {
path: path.resolve(__dirname + '/')
filename: 'bundle.js',
publicPath: '/'
},
devServer: {
contentBase: './',
inline: true,
hot: true,
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
query: {
presets: ['react']
}
}
]
}
};
What I have done here is add some missing configuration options according to this doc. configuration. Note my addition of the path import
I have also modified some of your configuration options slightly.
Related
I was trying to run my webpack inside my windows 10 machine.
I set up the webpack inside my root folder.
Here's my webpack.config.js:
const path = require("path");
const SRC_DIR = path.join(__dirname, "/client/src");
const DIST_DIR = path.join(__dirname, "client/dist");
module.exports = {
config: `${SRC_DIR}/index.jsx`,
output: {
filename: `bundle.js`,
path: DIST_DIR
},
module: {
rules: [
{
test: /\.jsx?$/,
include: SRC_DIR,
loader: "babel-loader",
query: {
presets: ["react", "es2015"]
}
}
]
},
mode: "development"
};
And then inside my package.json file:
{
"name": "rform",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"start": "node server.js",
"build": "webpack --config webpack.config.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-preset-es2015": "^6.24.1",
"webpack": "^4.12.0",
"webpack-command": "^0.2.1"
}
}
Upon running npm run build I got the ff error:
ValidationError: config-loader
Options Validation Error
options['config'] is an invalid additional property
at validate (/mnt/c/xampp/htdocs/rform/node_modules/#webpack-contrib/schema-utils/dist/validate-options.js:87:15)
at validator (/mnt/c/xampp/htdocs/rform/node_modules/#webpack-contrib/schema-utils/dist/validate-options.js:118:10)
at resolve.then (/mnt/c/xampp/htdocs/rform/node_modules/#webpack-contrib/config-loader/lib/index.js:18:7)
at process._tickCallback (internal/process/next_tick.js:109:7)
at Module.runMain (module.js:607:11)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)
at bootstrap_node.js:542:3
npm ERR! Linux 4.4.0-17134-Microsoft
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "build"
npm ERR! node v7.10.1
npm ERR! npm v4.2.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! rform#1.0.0 build: `webpack --config webpack.config.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the rform#1.0.0 build script 'webpack --config webpack.config.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the rform package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! webpack --config webpack.config.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs rform
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls rform
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/darrenchui/.npm/_logs/2018-06-13T07_55_50_484Z-debug.log
I make sure that I am running the proper the file setup inside my dist and src folder..What am I doing wrong on configuration? Please help!
There isn't anything called as the config in their webpack-configuration options
Kindly go through their configuration options from the below link
https://webpack.js.org/configuration/
I guess it will work if you replace config with entry in you options like below
module.exports = {
entry: `${SRC_DIR}/index.jsx`,
output: {
filename: `bundle.js`,
path: `DIST_DIR`
},
module: {
rules: [
{
test: /\.jsx?$/,
include: SRC_DIR,
exclude: /node_modules/,
loader: "babel-loader",
query: {
presets: ["react", "es2015"]
}
}
]
},
mode: "development"
};
When I run ./node_modules/.bin/webpack-dev-server to build, this error happens
The CLI moved into a separate package: webpack-cli.
Please install 'webpack-cli' in addition to webpack itself to use the CLI.
-> When using npm: npm install webpack-cli -D
-> When using yarn: yarn add webpack-cli -D
module.js:559
throw err;
^
Error: Cannot find module 'webpack-cli/bin/config-yargs'
at Function.Module._resolveFilename (module.js:557:15)
at Function.Module._load (module.js:484:25)
at Module.require (module.js:606:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/xxx/Downloads/react_app/node_modules/webpack-dev-server/bin/webpack-dev-server.js:65:1)
at Module._compile (module.js:662:30)
at Object.Module._extensions..js (module.js:673:10)
at Module.load (module.js:575:32)
at tryModuleLoad (module.js:515:12)
at Function.Module._load (module.js:507:3)
therefore I run npm install webpack-cli -D command and I run the command again but zsh: no such file or directory: ./node_modules/.bin/webpack-dev-server error happens.I followed procedure to build react.js so I think my building procedure has no error.So what should I do to fix this?Does this error cause difference of libraries version?How should I fix this?
My webpack.config.js is
var publidDir = __dirname + '/public';
module.exports = {
entry: [
'./src/index.js'
],
output: {
path: publidDir,
publicPath: '/',
filename: 'bundle.js'
},
module: {
loaders: [{
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['react', 'es2015']
}
}]
},
resolve: {
extensions: ['.js', '.jsx']
},
devServer: {
historyApiFallback: true,
contentBase: publidDir
}
};
I was having the same problem after update some dependencies. Check the webpack-dev-server version, I had 3.1.3 and I was getting same error as you. This what I have right now:
"webpack": "^3.10.0",
"webpack-dev-server": "2.9.7"
include below versions on your package.json file:
"dependencies": {
"webpack": "^3.10.0",
"webpack-dev-server": "2.9.7"
},
You're missing webpack-dev-server you need to install it with
npm install webpack-dev-server -D
or if using yarn
yarn add webpack-dev-server -D
If I use this to run:
webpack-dev-server --progress webpack.config.js
There are many errors like this:
ERROR in ./~/chokidar/lib/nodefs-handler.js
Module not found: Error: Cannot resolve module 'fs' in E:\study\s-webpack\node_modules\chokidar\lib
# ./~/chokidar/lib/nodefs-handler.js 3:9-22
However, if I use these to run:
webpack-dev-server --progress
webpack-dev-server --progress --color webpack.config.js
There is no error.
Here is the code repo: https://github.com/qlqllu/react-webpack-simple/tree/test
It's a very simple react and webpack project.
Please use:
npm run good
npm run good2
npm run bad
to test.
Just add this to your webpack config
node: {
fs: "empty"
}
Read more about webpack configuration here
Then it'll be like
module.exports = {
entry: './main.js',
output: { path: __dirname, filename: 'bundle.js' },
module: {
loaders: [
{
test: /.jsx?$/,
loader: 'babel-loader',
query: {
presets: ['es2015', 'react']
}
}
]
},
node: {
fs: "empty"
}
};
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.
Here's my webpack-dev-server configuations
module.exports = {
entry: './main.js',
output: {
path: './',
filename: 'bundle.js'
},
devServer: {
inline: true,
port: 9000
},
module: {
loaders: [{
test: /\.js$/,
exclude: '/(node_modules)/',
loader: 'babel',
query: {
presets: ['es2015', 'react']
}
}]
}
};
Why would I get the following error when I run the server
ERROR in (webpack)-dev-server/~/strip-ansi/index.js
Module build failed: Error: Couldn't find preset "react" relative to directory "/Users/ecco/.nvm/versions/node/v5.4.0/lib/node_modules/webpack-dev-server/node_modules/strip-ansi"
my package.json
"devDependencies": {
"babel-core": "^6.4.5",
"babel-loader": "^6.2.2",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"webpack": "^1.12.13"
}
You don't appear to have the webpack-dev-server installed as a local node module (it's not in your package.json
You can see which modules are installed locally and globally with npm list and npm list --global. To look for specific modules, pipe that command into grep i.e. npm list --global | grep webpack-dev-server
I'd suggest installing the dev server as a devDependency of your project. As a general rule, try to avoid installing modules with -g unless absolutely necessary. Also, use npm scripts (in your package.json) to run modules in your local directory, without having to reference them explicitly e.g.
{
"scripts": {
"serve": "webpack-dev-server --config your.config.js"
}
}
then run npm run serve rather than running ./node_modules/.bin/webpack-dev-server --config your.config.js (or worse, installing it globally)