electron / get

Download Electron release artifacts
https://npm.im/@electron/get
MIT License
338 stars 106 forks source link

`ERR_REQUIRE_ESM` error when trying to install electron #231

Closed keganlance closed 2 years ago

keganlance commented 2 years ago

When trying to install electron using: pnpm install electron --save-dev

I get the error:

 EACCES  EACCES: permission denied, mkdir '/node_modules/.pnpm/global-agent@3.0.0/node_modules/_tmp_86012_2f2ba15245ff2a054dcb4fa80c2b849f

So I try with sudo:: sudo pnpm install electron --save-dev

Yet get the following error:

node_modules/.pnpm/electron@20.1.1/node_modules/electron: Running postinstall script, failed in 157ms
.../node_modules/electron postinstall$ node install.js
│ Error [ERR_REQUIRE_ESM]: require() of ES Module /node_modules/.pnpm/got@12.4.1/node_modules/got/dist/source/index.js from /node_modules/.pnpm/@electron+get@1.14.1/node_modules/@electron/get/dist/cjs/GotDow
│ Instead change the require of index.js in /node_modules/.pnpm/@electron+get@1.14.1/node_modules/@electron/get/dist/cjs/GotDownloader.js to a dynamic import() which is available in all CommonJS modules.
│     at Object.<anonymous> (/node_modules/.pnpm/@electron+get@1.14.1/node_modules/@electron/get/dist/cjs/GotDownloader.js:15:13)
│     at /node_modules/.pnpm/@electron+get@1.14.1/node_modules/@electron/get/dist/cjs/downloader-resolver.js:8:66
│     at async Object.getDownloaderForSystem (/node_modules/.pnpm/@electron+get@1.14.1/node_modules/@electron/get/dist/cjs/downloader-resolver.js:8:31)
│     at async /node_modules/.pnpm/@electron+get@1.14.1/node_modules/@electron/get/dist/cjs/index.js:67:59
│     at async useAndRemoveDirectory (/node_modules/.pnpm/@electron+get@1.14.1/node_modules/@electron/get/dist/cjs/utils.js:10:18)
BlackHole1 commented 2 years ago

In my local is normal.

image

Please make sure your node version is above 12.

keganlance commented 2 years ago

The permission denied issue has been solved after a reboot. However, I'm still getting the ERR_REQUIRE_ESM issue. Running node v18.8.0, and pnpm v7.9.3.

After further investigation, it seems a compiled file /dist/cjs/GotDownloader.js from electron-get, is trying to require the ESM module got.

The full warning:

Error [ERR_REQUIRE_ESM]: require() of ES Module /node_modules/.pnpm/got@12.4.1/node_modules/got/dist/source/index.js from /node_modules/.pnpm/@electron+get@1.14.1/node_modules/@electron/get/dist/cjs/GotDownloader.js not supported.

A subset of /dist/cjs/GotDownloader.js:

Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs-extra");
const got_1 = require("got");
const path = require("path");
const ProgressBar = require("progress");
const PROGRESS_BAR_DELAY_IN_SECONDS = 30;
class GotDownloader {
    async download(url, targetFilePath, options) {
        ...
    }
}
exports.GotDownloader = GotDownloader;
//# sourceMappingURL=GotDownloader.js.map

The got file /dist/source/index.js:

import create from './create.js';
import Options from './core/options.js';
const defaults = {
    options: new Options(),
    handlers: [],
    mutableDefaults: false,
};
const got = create(defaults);
export default got;
export { got };
export { default as Options } from './core/options.js';
export * from './core/options.js';
export * from './core/response.js';
export * from './core/index.js';
export * from './core/errors.js';
export { default as calculateRetryDelay } from './core/calculate-retry-delay.js';
export * from './as-promise/types.js';
export * from './types.js';
export { default as create } from './create.js';
export { default as parseLinkHeader } from './core/parse-link-header.js';
keganlance commented 2 years ago

Seems another package in combination with pnpm audit added this because of known security issues:

  "pnpm": {
    "overrides": {
      "got@<11.8.5": ">=11.8.5"
    }
  }

Which might have caused the above issue.

BlackHole1 commented 2 years ago

It seems to be caused by other dependencies, is it possible for you to make a separate test case with only the necessary code to reproduce the problem?

keganlance commented 2 years ago

Issue has been resolved by removing the "pnpm.overrides" from package.json. It would be solved 100% if electron/get would use the latest GOT version but this might not be doable due to incompatibilities.