18

I'm attempting to use webpack for the first time and I'm getting this error,

Error: EACCES: permission denied, mkdir '/dist'
    at Error (native)

when trying to run my production script.

A sudo chown -R 'whoami' /dist came back with chown: /dist: No such file or directory.

How can I go about resolving this?

CalAlt
  • 1,683
  • 2
  • 15
  • 29

2 Answers2

34

As Camp bell mentioned you need to remove forward slash before dist folder in the output path section.

In my case I had to remove forward slash before build. Check my example below

Wrong one:

output: {
    path: path.resolve(__dirname, "/build/"), //remove forward slash here
    publicPath: "/",
    filename: "bundle.js"
}

Correct one:

output: {
    path: path.resolve(__dirname, "build/"),
    publicPath: "/",
    filename: "bundle.js"
}

Hope this helps.

Hemadri Dasari
  • 32,666
  • 37
  • 119
  • 162
0

Usually, in this case, it's likely that permission denied is just a result, not a real cause of error.

Most likely, you carelessly wrote ./ as / in the configuration code. Because, npm really can't access path /; this path is outside the user directory ~. npm, usually installed in the user directory. Just like:

$ type npm
npm is /Users/somebody/.nvm/versions/node/v12.2.0/bin/npm

So, Check the configuration file carefully. Hope to help you.

Bernard
  • 89
  • 4