Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught ReferenceError: __dirname is not defined #97

Closed
linonetwo opened this issue Aug 30, 2020 · 3 comments
Closed

Uncaught ReferenceError: __dirname is not defined #97

linonetwo opened this issue Aug 30, 2020 · 3 comments

Comments

@linonetwo
Copy link

When used in the electron project it cause this bug with nodeIntegration: false.

In this last line:

/******/ 	// Object.prototype.hasOwnProperty.call
/******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "/";
/******/
/******/ 	// __webpack_hash__
/******/ 	__webpack_require__.h = function() { return hotCurrentHash; };
/******/ 	__webpack_require__.ab = __dirname + "/native_modules/";

@linonetwo
Copy link
Author

Just only use it in main process fixes this.

  module: {
    rules: [
      ...require('./webpack.rules'),
      {
        test: /\.(m?js|node)$/,
        parser: { amd: true },
        use: {
          loader: '@zeit/webpack-asset-relocator-loader',
          options: {
            outputAssetBase: 'native_modules',
            emitDirnameAll: true,
          },
        },
      },
    ],
  },

@Sanford284
Copy link

Sanford284 commented Jul 19, 2023

I use electron, when use this plugin in renderer process build, same error.
image

webpack config:

target: 'web',
node: {
        __dirname: false, // any value not work
    },

it seem to elevate the code to the top of the file

@linonetwo
Copy link
Author

@yuwanlin My experience is try not import any node related npm package or ts file in renderer/preload.

If do so, there will be error like this. You can time travel in git to find which commit introduce such an import.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants