【问题标题】:Webpack with target node/electron-main not recognizing import node:process带有目标节点/电子主节点的 Webpack 无法识别导入节点:进程
【发布时间】:2026-02-02 13:45:02
【问题描述】:

我更新了节点模块fix-path因为它间歇性地崩溃了。

更新节点模块后,我无法在 main.js 文件中使用它,因为它会引发以下错误:

因此,我没有在主 js 中使用它,而是将这段代码移动到另一个文件中,该文件通过 webpack 构建过程。但随后 webpack 构建失败,因为它无法识别 'node:process'。

ERROR in ./node_modules/default-shell/index.js
Module not found: Error: Can't resolve 'node:os' in '/Users/shashi/projects/trici-atman-desktop/node_modules/default-shell'
resolve 'node:os' in '/Users/shashi/projects/trici-atman-desktop/node_modules/default-shell'
  Parsed request is a module
  using description file: /Users/shashi/projects/trici-atman-desktop/node_modules/default-shell/package.json (relative path: .)
    resolve as module
      /Users/shashi/projects/trici-atman-desktop/node_modules/default-shell/node_modules doesn't exist or is not a directory
      /Users/shashi/projects/trici-atman-desktop/node_modules/node_modules doesn't exist or is not a directory
      /Users/shashi/projects/node_modules doesn't exist or is not a directory
      /Users/shashi/node_modules doesn't exist or is not a directory
      /Users/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory
      looking for modules in /Users/shashi/projects/trici-atman-desktop/node_modules
        using description file: /Users/shashi/projects/trici-atman-desktop/package.json (relative path: ./node_modules)
          using description file: /Users/shashi/projects/trici-atman-desktop/package.json (relative path: ./node_modules/node:os)
            no extension
              /Users/shashi/projects/trici-atman-desktop/node_modules/node:os doesn't exist
            *
              /Users/shashi/projects/trici-atman-desktop/node_modules/node:os* doesn't exist
            .js
              /Users/shashi/projects/trici-atman-desktop/node_modules/node:os.js doesn't exist
            .json
              /Users/shashi/projects/trici-atman-desktop/node_modules/node:os.json doesn't exist
            as directory
              /Users/shashi/projects/trici-atman-desktop/node_modules/node:os doesn't exist
[/Users/shashi/projects/trici-atman-desktop/node_modules/default-shell/node_modules]
[/Users/shashi/projects/trici-atman-desktop/node_modules/node_modules]
[/Users/shashi/projects/node_modules]
[/Users/shashi/node_modules]
[/Users/node_modules]
[/node_modules]
[/Users/shashi/projects/trici-atman-desktop/node_modules/node:os]
[/Users/shashi/projects/trici-atman-desktop/node_modules/node:os*]
[/Users/shashi/projects/trici-atman-desktop/node_modules/node:os.js]
[/Users/shashi/projects/trici-atman-desktop/node_modules/node:os.json]
 @ ./node_modules/default-shell/index.js 2:0-33 12:18-26
 @ ./node_modules/shell-env/index.js
 @ ./node_modules/shell-path/index.js
 @ ./node_modules/fix-path/index.js
 @ ./desktopServices/AppService.js
 @ ./desktopServices/desktopServices.js

看到this 问题的答案后,我尝试将我的webpack 的目标从electron-main 更改为node。但它还是不认识。

我该如何解决这个问题?

【问题讨论】:

    标签: javascript node.js webpack electron


    【解决方案1】:

    通过将 webpack 从 4 升级到 5 解决了这个问题。

    【讨论】:

      最近更新 更多