P
P
pegas2018-05-09 17:37:59
Node.js
pegas, 2018-05-09 17:37:59

Why does the __dirname variable show the wrong path?

In webpack 4, I created a src folder and an index.j file in it, in which I wrote alert(__dirname);
In the console, I run webpack --mode production, then webpack-dev-server --mode development.
And in the browser alert gives me "/".
Although __dirname is the path to the folder with the file in which it is written and should be src

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2018-05-09
@rockon404

target: 'node',
node: {
  __dirname: false,
}

or:
plugins: [
  new webpack.DefinePlugin({
    $dirname: '__dirname',
  }),
]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question