yeoman / yo

CLI tool for running Yeoman generators
http://yeoman.io
BSD 2-Clause "Simplified" License
3.84k stars 398 forks source link

Cannot find package 'mem-fs' imported from #800

Open chk4658 opened 9 months ago

chk4658 commented 9 months ago

Type of issue

npm install -g yo generator-code

and yo code failed

C:\Users\KHC1SZH\chenkai\Projects\vscodePluginsDemo>yo code Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'mem-fs' imported from C:\Users\KHC1SZH\chenkai\node-v14.17.2-win-x64\node_global\node_modules\yo\node_modules\yeoman-environment\dist\environment-base.js at packageResolve (internal/modules/esm/resolve.js:650:9) at moduleResolve (internal/modules/esm/resolve.js:691:18) at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:805:11) at Loader.resolve (internal/modules/esm/loader.js:88:40) at Loader.getModuleJob (internal/modules/esm/loader.js:241:28) at ModuleWrap. (internal/modules/esm/module_job.js:72:40) at link (internal/modules/esm/module_job.js:71:36)


My environment

C:\Users\KHC1SZH\chenkai\Projects\vscodePluginsDemo>node --version v14.17.2

C:\Users\KHC1SZH\chenkai\Projects\vscodePluginsDemo>npm --version 6.14.13

C:\Users\KHC1SZH\chenkai\Projects\vscodePluginsDemo>yo --version 5.0.0

Expected behavior

Need an upgrade for node? or downgrade yo. What should I do?

Current behavior

C:\Users\KHC1SZH\chenkai\Projects\vscodePluginsDemo>npm install -g mem-fs npm WARN notsup Unsupported engine for mem-fs@4.0.0: wanted: {"node":">=18.0.0"} (current: {"node":"14.17.2","npm":"6.14.13"}) npm WARN notsup Not compatible with your version of node/npm: mem-fs@4.0.0

C:\Users\KHC1SZH\chenkai\Projects\vscodePluginsDemo>yo code Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'stream' imported from C:\Users\KHC1SZH\chenkai\node-v14.17.2-win-x64\node_global\node_modules\mem-fs\dist\index.js at packageResolve (internal/modules/esm/resolve.js:650:9) at moduleResolve (internal/modules/esm/resolve.js:691:18) at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:805:11) at Loader.resolve (internal/modules/esm/loader.js:88:40) at Loader.getModuleJob (internal/modules/esm/loader.js:241:28) at ModuleWrap. (internal/modules/esm/module_job.js:72:40) at link (internal/modules/esm/module_job.js:71:36)

Steps to reproduce the behavior

Command line output

Paste your error output over here
1071125093 commented 9 months ago

same

1071125093 commented 9 months ago

stiff but fixed 1.need nvm, install node 20.5.0 2.reinstall yo generator-code

filipboca commented 8 months ago

Same for me, still does not work on 20.5

atulbhatt-system32 commented 8 months ago

I am also facing the same issue

mshima commented 8 months ago

C:\Users\KHC1SZH\chenkai\Projects\vscodePluginsDemo>node --version v14.17.2

C:\Users\KHC1SZH\chenkai\Projects\vscodePluginsDemo>npm --version 6.14.13

yo@5 requires node 18 and npm should be at least v7, latest is recommended.

atulbhatt-system32 commented 8 months ago

I tried with node -v (21.5.0) and npm -v (10.2.4) but what worked for me was downgrading yo to version 4.3.1

atulbhatt-system32 commented 8 months ago

@mshima is node 18 the minimum requirement or greater also works for yo@5 as in my case it didn't. node -v (21.5.0) and npm -v (10.2.4)

mshima commented 8 months ago

yo must be installed with newer npm (must support peer dependencies).

npm install -g npm@latest
npm uninstall -g yo generator-code
npm install -g yo generator-code
npm uninstall yo generator-code # make sure it’s not installed locally
yo code
isMattCoding commented 3 months ago

Playing with the npm and node versions didn't work for me.

It seems that this issue still persists, but what allowed me to continue was running:

npm install -g yo generator-code mem-fs
yo code
erikJonsberg commented 2 weeks ago

Playing with the npm and node versions didn't work for me.

It seems that this issue still persists, but what allowed me to continue was running:

npm install -g yo generator-code mem-fs
yo code

This worked for me as well. However, I need to reinstall mem-fs globally each time I run yo code. Does anyone know why? It should already be installed, right?

schroeder-g commented 1 week ago

Playing with the npm and node versions didn't work for me. It seems that this issue still persists, but what allowed me to continue was running:

npm install -g yo generator-code mem-fs
yo code

This worked for me as well. However, I need to reinstall mem-fs globally each time I run yo code. Does anyone know why? It should already be installed, right?

The above alone didn't resolve the issue for me. The fix that I found was to:

  1. Uninstall all the relevant packages, nvm use v20.14.0, npm install -g yo generator-code mem-fs
  2. navigate to the install location for yeoman indicated in the error: code /path/to/node_modules/yeoman-generator
  3. npm install mem-fs
  4. npm run build to recompile dist with tsc.
  5. yo > choose generator.

Hilariously, there's no tsconfig.json in the project, so the build step resulted in me transpiling all TypeScript files in my home directory. Would recommend just copying theirs into the project root to avoid this issue.