简体   繁体   English

找不到模块:错误无法解析“child_process”,如何解决?

[英]Module not found: Error can't resolve 'child_process', how to fix?

I'm trying to create a JupyterLab extension, it uses typescript.我正在尝试创建一个 JupyterLab 扩展,它使用 typescript。

I've successfully added the package "@types/node" allowing me to use packages such as 'require('http')'.我已成功添加 package“@types/node”,允许我使用诸如“require('http')'之类的包。

But as soon as I try to use child process, using 'require("child_process")' I get the following error when trying to build the extension.但是,一旦我尝试使用子进程,使用'require(“child_process”)',我在尝试构建扩展时就会收到以下错误。

ModuleNotFoundError: Module not found: Error: Can't resolve 'child_process' in '/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/jupyerlab_xkdc/lib'
    at factory.create (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/webpack/lib/Compilation.js:535:10)
    at factory (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/webpack/lib/NormalModuleFactory.js:397:22)
    at resolver (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/webpack/lib/NormalModuleFactory.js:130:21)
    at asyncLib.parallel (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/webpack/lib/NormalModuleFactory.js:224:22)
    at /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/neo-async/async.js:2825:7
    at /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/neo-async/async.js:6886:13
    at normalResolver.resolve (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/webpack/lib/NormalModuleFactory.js:214:25)
    at doResolve (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/Resolver.js:184:12)
    at hook.callAsync (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
    at _fn0 (eval at create (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:15:1)
    at resolver.doResolve (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:37:5)
    at hook.callAsync (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
    at _fn0 (eval at create (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:15:1)
    at hook.callAsync (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
    at _fn0 (eval at create (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:12:1)
    at resolver.doResolve (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:42:38)
    at hook.callAsync (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
    at _fn41 (eval at create (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:381:1)
    at resolver.doResolve (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/ModuleKindPlugin.js:23:37)
    at hook.callAsync (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
    at _fn0 (eval at create (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:15:1)
    at hook.callAsync (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
    at _fn0 (eval at create (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:15:1)
    at args (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/forEachBail.js:30:14)
    at hook.callAsync (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
    at _fn0 (eval at create (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:15:1)
    at resolver.doResolve (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:37:5)
    at hook.callAsync (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/Resolver.js:238:5)
    at _fn0 (eval at create (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:15:1)
    at hook.callAsync (/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/enhanced-resolve/lib/Resolver.js:238:5) resolve 'child_process' in '/home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/jupyerlab_xkdc/lib' Parsed request is a module   using description file: /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/jupyerlab_xkdc/package.json (relative path: ./lib)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/jupyerlab_xkdc/lib/node_modules doesn't exist or is not a directory
      /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/node_modules doesn't exist or is not a directory
      /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/node_modules doesn't exist or is not a directory
      /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/node_modules doesn't exist or is not a directory
      /home/fionn/anaconda3/envs/jupyterlab-ext/share/node_modules doesn't exist or is not a directory
      /home/fionn/anaconda3/envs/jupyterlab-ext/node_modules doesn't exist or is not a directory
      /home/fionn/anaconda3/envs/node_modules doesn't exist or is not a directory
      /home/fionn/anaconda3/node_modules doesn't exist or is not a directory
      /home/fionn/node_modules doesn't exist or is not a directory
      /home/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory
      looking for modules in /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/jupyerlab_xkdc/node_modules
        using description file: /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/jupyerlab_xkdc/package.json (relative path: ./node_modules)
          Field 'browser' doesn't contain a valid alias configuration
      looking for modules in /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules
        using description file: /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/package.json (relative path: ./node_modules)
          Field 'browser' doesn't contain a valid alias configuration
          using description file: /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/child_process/package.json (relative path: .)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
          using description file: /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/jupyerlab_xkdc/package.json (relative path: ./node_modules/child_process)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/child_process is not a file
            .wasm
              Field 'browser' doesn't contain a valid alias configuration
              /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/jupyerlab_xkdc/node_modules/child_process doesn't exist
            .wasm
              Field 'browser' doesn't contain a valid alias configuration
              /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/child_process.wasm doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/jupyerlab_xkdc/node_modules/child_process.wasm doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/child_process.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/jupyerlab_xkdc/node_modules/child_process.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/child_process.js doesn't exist
            .json
              Field 'browser' doesn't contain a valid alias configuration
              /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/jupyerlab_xkdc/node_modules/child_process.js doesn't exist
            .json
              Field 'browser' doesn't contain a valid alias configuration
              /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/child_process.json doesn't exist
              /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/jupyerlab_xkdc/node_modules/child_process.json doesn't exist
            as directory
              existing directory
                use ./index.js from main in package.json
                  using description file: /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/child_process/package.json (relative path: .)
                    Field 'browser' doesn't contain a valid alias configuration
            as directory
              /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/jupyerlab_xkdc/node_modules/child_process doesn't exist
                    using description file: /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/child_process/package.json (relative path: ./index.js)
                      no extension
                        Field 'browser' doesn't contain a valid alias configuration
                        /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/child_process/index.js doesn't exist
                      .wasm
                        Field 'browser' doesn't contain a valid alias configuration
                        /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/child_process/index.js.wasm doesn't exist
                      .mjs
                        Field 'browser' doesn't contain a valid alias configuration
                        /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/child_process/index.js.mjs doesn't exist
                      .js
                        Field 'browser' doesn't contain a valid alias configuration
                        /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/child_process/index.js.js doesn't exist
                      .json
                        Field 'browser' doesn't contain a valid alias configuration
                        /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/child_process/index.js.json doesn't exist
                      as directory
                        /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/child_process/index.js doesn't exist
                using path: /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/child_process/index
                  using description file: /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/child_process/package.json (relative path: ./index)
                    no extension
                      Field 'browser' doesn't contain a valid alias configuration
                      /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/child_process/index doesn't exist
                    .wasm
                      Field 'browser' doesn't contain a valid alias configuration
                      /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/child_process/index.wasm doesn't exist
                    .mjs
                      Field 'browser' doesn't contain a valid alias configuration
                      /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/child_process/index.mjs doesn't exist
                    .js
                      Field 'browser' doesn't contain a valid alias configuration
                      /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/child_process/index.js doesn't exist
                    .json
                      Field 'browser' doesn't contain a valid alias configuration
                      /home/fionn/anaconda3/envs/jupyterlab-ext/share/jupyter/lab/staging/node_modules/child_process/index.json doesn't exist error Command failed with exit code 1.

I've googled around but still have no idea what to do to resolve this issue.我已经四处搜索,但仍然不知道如何解决这个问题。

Any pointers or info at all would be greatly appreciated.任何指针或信息都将不胜感激。

My packages.json file.我的 packages.json 文件。

{
  "name": "jupyerlab_xkdc",
  "version": "0.1.0",
  "description": "Short description",
  "keywords": [
    "jupyter",
    "jupyterlab",
    "jupyterlab-extension"
  ],
  "homepage": "https://github.com/my_name/myextension",
  "bugs": {
    "url": "https://github.com/my_name/myextension/issues"
  },
  "license": "BSD-3-Clause",
  "author": "Fionn McKnight",
  "files": [
    "lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
    "style/**/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf}"
  ],
  "main": "lib/index.js",
  "types": "lib/index.d.ts",
  "repository": {
    "type": "git",
    "url": "https://github.com/my_name/myextension.git"
  },
  "scripts": {
    "build": "tsc",
    "clean": "rimraf lib",
    "prepare": "npm run clean && npm run build",
    "watch": "tsc -w"
  },
  "dependencies": {
    "@jupyterlab/application": "^0.19.1",
    "@jupyterlab/apputils": "^0.19.1",
    "@phosphor/coreutils": "^1.3.0",
    "@phosphor/messaging": "^1.2.2",
    "@phosphor/widgets": "^1.6.0",
    "@types/jquery": "^3.3.29",
    "@types/node": "^10.12.19",
    "child_process": "^1.0.2",
    "npm": "^6.7.0"
  },
  "devDependencies": {
    "@types/node": "^10.12.19",
    "rimraf": "^2.6.1",
    "typescript": "~3.1.1"
  },
  "jupyterlab": {
    "extension": true
  }
}

just put in package.json只需放入 package.json

"browser":{
"child_process": false
}  

are you using webpack你在用 webpack

I got a similar error while trying to run storybook.js which uses webpack .我在尝试运行使用webpack 的storybook.js时遇到了类似的错误。

For Webpack对于 Webpack

You can add the following to the webpack's config to fix the build -您可以将以下内容添加到 webpack 的配置中以修复构建 -

// webpack.config.js
...,
node: {
    child_process: "empty"
    // fs: "empty", // if unable to resolve "fs"
},

You can also set other conflicting modules to "empty" if they are responsible for breaking the build.如果其他冲突模块负责破坏构建,您还可以将它们设置为"empty"

Reference for Webpack's config.node Webpack 的 config.node 参考

In newer versions I used:在我使用的较新版本中:

// webpack.config.js
...,
resolve: {
    extensions: [".ts", ".js"],
    fallback: {
      "child_process": false,
      // and also other packages that are not found
    }
  },

Randomly Got this issue while using next.js I got it resolved by clearing out,使用next.js时随机遇到这个问题我通过清除解决了它,

.next
node_modules 

folders Guess it may work for people getting this client process error in next js文件夹猜测它可能适用于在下一个 js 中收到此客户端进程错误的人

I got this in next.js after importing path and fs in a page.页面中导入pathfs后,我在next.js 中得到了这个。

Solved it by placing them in the getStaticProps() function.通过将它们放在getStaticProps()函数中来解决它。

Same happened同样发生

Figured out why it happened弄清楚为什么会发生

By mistake import was added to file that created issue错误地将导入添加到创建问题的文件中

import { debug } from "webpack";

I stayed blocked for couple of time on that.我在这方面被阻止了几次。 As far I understood, it seems impossible to execute some child_process ( which is literally executing some cmd ) from the browser, which also make sense at some point.. The solution given works for me, adding below to package.json is working据我了解,似乎不可能从浏览器执行一些 child_process (实际上是执行一些 cmd ),这在某些时候也有意义..给出的解决方案对我有用,在下面添加到package.json正在工作

  "browser": { "fs": false, "child_process": false }

But don't add it on your package.json (mean the one of your app ), but instead the package.json from the lib than you are using where the require('child_process') is.但是不要将它添加到你的 package.json (意味着你的应用程序之一),而是来自 lib 的 package.json 而不是你使用的require('child_process')所在的位置。

That's being done, this fixe just said to the compiler that's it's ok to not have a lib even if this one is required somewhere on your code or dependencies (rather to crash ).这已经完成了,这个修复程序只是对编译器说,即使您的代码或依赖项的某处需要这个库(而不是崩溃),也可以没有库。 If you want to use child_process from your App i am afraid that it's complicated.如果你想从你的应用程序中使用 child_process 恐怕它很复杂。

Here is the source of my post这是我帖子的来源

Choose call exec into main.ts electron in ipcrender, work fine在 ipcrender 中选择 call exec 进入 main.ts electron,工作正常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到模块:无法解析“ child_process” - Module not found: Can't resolve 'child_process' 无法解析模块“child_process” - Can't resolve module 'child_process' Next.js - 使用 BigQuery 客户端库时出现错误:找不到模块:无法解析“child_process” - Next.js - using BigQuery client library gives an error : Module not found: Can't resolve 'child_process' 无法解析模块xmlhttprequest中的“ child_process” - Can't Resolve “child_process” in module xmlhttprequest 错误:无法解析'child_process'Angular-cli - Error: Can't resolve 'child_process' Angular-cli 无法解析“child_process” - Can't resolve 'child_process' 我正在尝试将 NPM package 作为插件注入到 Next.js 应用程序上,以避免出现“找不到模块:无法解析‘child_process’”错误 - I'm Trying to Inject An NPM package As A Plugin on A Next.js App to Avoid A "Module not found: Can't resolve 'child_process'" Error 错误:无法解析“child_process”和错误:无法解析“fs” - Error: Can't resolve 'child_process' and Error: Can't resolve 'fs' 在audiosprite中加载错误-找不到模块:“ child_process” - Error loading in audiosprite - Module not found: 'child_process' 使用Nodemailer和Webpack时无法解析dns和child_process - Can't resolve dns and child_process when using Nodemailer and Webpack
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM