最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - npm run build > bundle.js not getting created - Stack Overflow

programmeradmin1浏览0评论

I've looked several Q&A with people experiencing the same problem, but I still can't find what it wrong in my code.

No bundle.js file get created when running: sudo npm run build **

Here is my code:

index.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Cocinando Con Lalinde</title>
</head>
<body>
    <div id="app"></div>
    <script src="index.js"></script>
</body>
</html> 

package.json

{ 
  "name": "Cocinando-con-Lalinde",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "webpack-dev-server --hot",
    "build": "webpack"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "react": "^16.0.0",
    "react-dom": "^16.0.0",
    "styled-ponents": "^2.4.0"
  },
  "devDependencies": {
    "babel-preset-env": "^1.6.1",
    "json-loader": "^0.5.7",
    "webpack": "^3.8.1",
    "webpack-dev-server": "^2.9.3"
  }
}

webpack.config.js

var config = { 
     entry: './main.js',

     output: {
        path:'/',
        filename: 'bundle.js'
     },

     devServer: {
        inline: true,
        port: 8080
     },

     module: {
        loaders: [
           {
              test: /\.js$/,
              exclude: /node_modules/,
              loader: 'babel-loader',
              query: {
                 presets: ['es2015', 'react']
              }
           }
        ]
     }
  }

  module.exports = config;

I tried several tips and nothing works, bundle.js is not created.

Does someone has an clue about it?


** By the way, access permission denied when running npm run build, here's what I got:

Error: EACCES: permission denied, open '/bundle.js' at Error (native)

Does someone know why?


I've looked several Q&A with people experiencing the same problem, but I still can't find what it wrong in my code.

No bundle.js file get created when running: sudo npm run build **

Here is my code:

index.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Cocinando Con Lalinde</title>
</head>
<body>
    <div id="app"></div>
    <script src="index.js"></script>
</body>
</html> 

package.json

{ 
  "name": "Cocinando-con-Lalinde",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "webpack-dev-server --hot",
    "build": "webpack"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "react": "^16.0.0",
    "react-dom": "^16.0.0",
    "styled-ponents": "^2.4.0"
  },
  "devDependencies": {
    "babel-preset-env": "^1.6.1",
    "json-loader": "^0.5.7",
    "webpack": "^3.8.1",
    "webpack-dev-server": "^2.9.3"
  }
}

webpack.config.js

var config = { 
     entry: './main.js',

     output: {
        path:'/',
        filename: 'bundle.js'
     },

     devServer: {
        inline: true,
        port: 8080
     },

     module: {
        loaders: [
           {
              test: /\.js$/,
              exclude: /node_modules/,
              loader: 'babel-loader',
              query: {
                 presets: ['es2015', 'react']
              }
           }
        ]
     }
  }

  module.exports = config;

I tried several tips and nothing works, bundle.js is not created.

Does someone has an clue about it?


** By the way, access permission denied when running npm run build, here's what I got:

Error: EACCES: permission denied, open '/bundle.js' at Error (native)

Does someone know why?


Share Improve this question asked Jan 10, 2018 at 18:23 mepolpmepolp 531 silver badge3 bronze badges 1
  • If the answer I posted below works for you please mark it accepted. Thank you! – Joshua Underwood Commented Jan 11, 2018 at 1:47
Add a ment  | 

1 Answer 1

Reset to default 7

You're setting path to '/' which is relative to your systems file structure. You're likely generating the bundle file in your home directory.

This also explains the access denied because you wouldn't have write permissions to your root folder in Mac or linux without sudo

Change path to

path: __dirname + '/dist'

or some other folder you might want to use.

发布评论

评论列表(0)

  1. 暂无评论