wbyoung / avn

Automatic Version Switching for Node
MIT License
1.14k stars 54 forks source link

Cannot find module #105

Closed verpixelt closed 3 years ago

verpixelt commented 4 years ago

On node 14.5.0 when trying to switch to a folder with a .node-version folder the app throws the following error: Fatal Error: Cannot find module '/Users/verpixelt/.avn/plugins/avn-nvm' Details

The output of __avn_debug in the directory with a .node-version file is:

Fatal Error: Cannot find module '/Users/verpixelt/.avn/plugins/avn-nvm'.
Require stack:
- /Users/verpixelt/.avn/lib/plugins.js
- /Users/verpixelt/.avn/lib/hooks.js
- /Users/verpixelt/.avn/lib/avn.js
- /Users/verpixelt/.avn/index.js
- /Users/verpixelt/.avn/bin/_avn

avn is loaded in my ~/.{bash|zsh}{_profile|rc} file with:

`[[ -s "$HOME/.avn/bin/avn.sh" ]] && source "$HOME/.avn/bin/avn.sh" # load avn`
wbyoung commented 4 years ago

Does /Users/verpixelt/.avn/plugins/avn-nvm look like a module?

verpixelt commented 4 years ago

There are no plugins inside the folder.

wbyoung commented 4 years ago

Looks like you should try reinstalling.

rm -R ~/.avn

Then install.

verpixelt commented 4 years ago

This is what happens during setup:

avn setup
avn: profile setup complete (~/.zshrc)
avn: restart your terminal to start using avn
/usr/local/lib/node_modules/avn/node_modules/npm/node_modules/graceful-fs/polyfills.js:267
      if (cb) cb.apply(this, arguments)
                 ^

TypeError: cb.apply is not a function
    at /usr/local/lib/node_modules/avn/node_modules/npm/node_modules/graceful-fs/polyfills.js:267:18
    at FSReqCallback.oncomplete (fs.js:177:5)
wbyoung commented 4 years ago

That seems quite strange. Did that happen before when you ran the setup as well?

This is the type of thing I'd expect all users to experience if it wasn't something unique to your environment.

Any chance you can work on tracking down where the issue is coming from within avn?

Without more detail, I'm going to be honest, I doubt I'd be able to come up with a solution.

verpixelt commented 4 years ago

Thanks for your reply, @wbyoung. I've tried a few more things including switching from the latest node version at the time 14.5.0, to something lower. In my case I ran your avn setup with 10.0.0 and it worked 🎉 So I thought the node version might have been corrupted, removed it, re-installed 14.5.0 and it failed again, with the same error as posted above.

cb.apply is part of the polyfill.js in graceful-fs. Not sure tho why this would throw an error in my specific case. I've tried a fresh install on another machine. macOS 10.15.5, fresh n install, fresh node 14.5.0, same error on running avn setup.

wbyoung commented 4 years ago

Ok, could be part of a dependency issue and comparability. Perhaps upgrading all of the dependencies of the project would fix it.

I don't do much coding these days. If you want to give that a try, go for it & let me know or submit a PR.

lobanovkirill commented 4 years ago

Avn correct installed with node version 10.0.0 When i first installed Avn i used node version 14.6.0 and getting error, this error i gen and with node version 12.18.3 `/Users/usename/.nvm/versions/node/v12.18.3/lib/node_modules/avn/node_modules/npm/node_modules/graceful-fs/polyfills.js:267 if (cb) cb.apply(this, arguments) ^

TypeError: cb.apply is not a function at /Users/usename/.nvm/versions/node/v12.18.3/lib/node_modules/avn/node_modules/npm/node_modules/graceful-fs/polyfills.js:267:18 at FSReqCallback.oncomplete (fs.js:169:5)`

tybro0103 commented 4 years ago

+1

Setting up a new mac today. First tried to install with Node@12 and got the exact same thing as @lobanovkirill. Switched to Node@10 and it worked.

wbyoung commented 4 years ago

Thanks for confirming, @tybro0103.

PR welcome.

wbyoung commented 3 years ago

Closing this in favor of #106 which better represents the issue that @verpixelt had after reinstall.

konstantintieber commented 3 years ago

I ran into the same issue when updating from node 10.13.0 to 14.15.1 using nvm

~ $ cd dev/web-pathfinder
Fatal Error: Cannot find module '/Users/konstantintieber/.avn/plugins/avn-n'
Require stack:
- /Users/konstantintieber/.avn/lib/plugins.js
- /Users/konstantintieber/.avn/lib/hooks.js
- /Users/konstantintieber/.avn/lib/avn.js
- /Users/konstantintieber/.avn/index.js
- /Users/konstantintieber/.avn/bin/_avn

Fixed it as suggested by @wbyoung with:

rm -R ~/.avn
nvm exec 10.13.0 npm install -g avn avn-nvm avn-n
nvm exec 10.13.0 avn setup

EDIT: if you do not have the node 10 version installed yet, you have to run nvm install 10.13.0 before executing the commands above

ahmednawazkhan commented 2 years ago

Thanks @konstantintieber. It worked

cko-jimmy-wong commented 2 years ago

This seems to have stopped working for node 16, I keep getting the same TypeError again

wbyoung commented 2 years ago

@cko-jimmy-wong see/comment on #106, but please note the last comment in there about the lack of attention this project gets.