javascript - React, Webpack: bundle.js is not generated - Stack Overflow

admin2025-03-15  1

Edit: The reason was that I was running webpack-dev-server, when running just webpack it worked.

I am using React and Webpack. The bundle.js is not generated. I found this question on SO that brought up the same issue, but I seem to have the required dependencies installed. Here is my webpack.config.js:

var webpack = require('webpack');    
module.exports = {
    entry: [
        'webpack-dev-server/client?http://localhost:8080',
        'webpack/hot/only-dev-server',
        './src/index.js'
    ],
    module: {
        loaders: [{
            test: /\.js?$/,
            exclude: /node_modules/,
            loader: 'react-hot!babel'
        }]
    },
    resolve: {
        extensions: ['', '.js']
    },
    output: {
        path: 'dist',
        publicPath: '/',
        filename: 'bundle.js'
    },
    devServer: {
        contentBase: './dist',
        hot: true
    },
    plugins: [
        new webpack.HotModuleReplacementPlugin()
    ]
};

Here is my package.json:

{
  "name": "plump",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+.git"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "babel": {
    "presets": [
      "es2015",
      "react"
    ]
  },
  "bugs": {
    "url": ""
  },
  "homepage": "",
  "devDependencies": {
    "babel-core": "^6.8.0",
    "babel-loader": "^6.2.4",
    "babel-preset-es2015": "^6.6.0",
    "babel-preset-react": "^6.5.0",
    "react-hot-loader": "^1.3.0",
    "webpack": "^1.13.0",
    "webpack-dev-server": "^1.14.1"
  },
  "dependencies": {
    "history": "^2.1.1",
    "react": "^15.0.1",
    "react-dom": "^15.0.1",
    "react-router": "^2.4.0"
  }
}

Any idea?

Edit. Output when running webpack:

                               Asset      Size  Chunks             Chunk Names
                           bundle.js   1.19 MB       0  [emitted]  main
0.63b359d04fe48d6168fa.hot-update.js   27.9 kB       0  [emitted]  main
63b359d04fe48d6168fa.hot-update.json  36 bytes          [emitted]
chunk    {0} bundle.js, 0.63b359d04fe48d6168fa.hot-update.js (main) 1.11 MB [rendered]
  [318] ./src/ponents/LoginPage.js 8.93 kB {0} [built]
  [322] ./src/ponents/Lobby.js 12.2 kB {0} [built]
  [323] ./src/ponents/SignUp.js 5.6 kB {0} [built]
  [324] ./src/pages/Game.js 27.3 kB {0} [built]
     + 321 hidden modules
webpack: bundle is now VALID.

Edit: The reason was that I was running webpack-dev-server, when running just webpack it worked.

I am using React and Webpack. The bundle.js is not generated. I found this question on SO that brought up the same issue, but I seem to have the required dependencies installed. Here is my webpack.config.js:

var webpack = require('webpack');    
module.exports = {
    entry: [
        'webpack-dev-server/client?http://localhost:8080',
        'webpack/hot/only-dev-server',
        './src/index.js'
    ],
    module: {
        loaders: [{
            test: /\.js?$/,
            exclude: /node_modules/,
            loader: 'react-hot!babel'
        }]
    },
    resolve: {
        extensions: ['', '.js']
    },
    output: {
        path: 'dist',
        publicPath: '/',
        filename: 'bundle.js'
    },
    devServer: {
        contentBase: './dist',
        hot: true
    },
    plugins: [
        new webpack.HotModuleReplacementPlugin()
    ]
};

Here is my package.json:

{
  "name": "plump",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github./fiskpatte/plump.git"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "babel": {
    "presets": [
      "es2015",
      "react"
    ]
  },
  "bugs": {
    "url": "https://github./fiskpatte/plump/issues"
  },
  "homepage": "https://github./fiskpatte/plump#readme",
  "devDependencies": {
    "babel-core": "^6.8.0",
    "babel-loader": "^6.2.4",
    "babel-preset-es2015": "^6.6.0",
    "babel-preset-react": "^6.5.0",
    "react-hot-loader": "^1.3.0",
    "webpack": "^1.13.0",
    "webpack-dev-server": "^1.14.1"
  },
  "dependencies": {
    "history": "^2.1.1",
    "react": "^15.0.1",
    "react-dom": "^15.0.1",
    "react-router": "^2.4.0"
  }
}

Any idea?

Edit. Output when running webpack:

                               Asset      Size  Chunks             Chunk Names
                           bundle.js   1.19 MB       0  [emitted]  main
0.63b359d04fe48d6168fa.hot-update.js   27.9 kB       0  [emitted]  main
63b359d04fe48d6168fa.hot-update.json  36 bytes          [emitted]
chunk    {0} bundle.js, 0.63b359d04fe48d6168fa.hot-update.js (main) 1.11 MB [rendered]
  [318] ./src/ponents/LoginPage.js 8.93 kB {0} [built]
  [322] ./src/ponents/Lobby.js 12.2 kB {0} [built]
  [323] ./src/ponents/SignUp.js 5.6 kB {0} [built]
  [324] ./src/pages/Game.js 27.3 kB {0} [built]
     + 321 hidden modules
webpack: bundle is now VALID.
Share Improve this question edited May 23, 2017 at 11:46 CommunityBot 11 silver badge asked May 16, 2016 at 8:16 hellogoodnighthellogoodnight 2,1397 gold badges31 silver badges60 bronze badges 2
  • 1 What is the output when you run webpack? – Jayaram Commented May 16, 2016 at 8:22
  • I edited the question. Wierd, It seems at it is in deed generated, but I do not find it when I search the puter – hellogoodnight Commented May 16, 2016 at 8:25
Add a ment  | 

2 Answers 2

Reset to default 4

Theres probably something wrong with the output path .. can you try replacing the output path to ./dist

It is due to missing of some key-value pairs in scripts of package.json. Replace your scripts object with the following:

"scripts": {
    "start": "npm run build",
    "build": "webpack -p && webpack-dev-server"
  },

"-p" means specially for production evnvironment of webpack.config.js. Then run this cmd: $ npm start

$ npm start will invoke npm run build cmd which in turn will invoke "webpack -p && webpack-dev-server"

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1741985975a191403.html

最新回复(0)