link-module-alias
link-module-alias copied to clipboard
This deleted all my source files?
So I used yarn as usual to add a new dependancy and from the looks of it all my source that was symlinked via node_modules was removed.
Lucky I had just committed and could use git to retrieve the files but this looks like a huge issue.
PING: @Rush
I'm testing but I believe the pre-install script is what would have prevented this.
~Maybe there should be more than a small message in the readme about it? Personally I'd suggest having the package check for the preinstall hook and add it unless there's a flag passed.~
~Something like --no-install?~
So I used yarn as usual to add a new dependancy and from the looks of it all my source that was symlinked via node_modules was removed.
Wow, this sounds bad. Can you show me the structure of your project? Btw. just yesterday I discovered that it's possible to link subdirectories via a file: version specifier, is it the way of your project?
Maybe there should be more than a small message in the readme about it? Personally I'd suggest having the
packagecheck for thepreinstallhook and add it unless there's a flag passed.
Can you elaborate? I am not sure I understand.
link-module-alias shouldn't at any circumstances remove actual source code - this needs to be fixed.
Clone this repo and try the steps below. Not sure if this also happens with npm, just wanted to get this to you ASAP.
β delete-bug git:(master) rm -rf node_modules
β delete-bug git:(master) yarn
yarn install v1.12.3
warning package.json: No license field
warning No license field
[1/4] π Resolving packages...
[2/4] π Fetching packages...
[3/4] π Linking dependencies...
[4/4] π Building fresh packages...
$ link-module-alias
[####################] 20/20link-module-alias: @components -> ./components
β¨ Done in 0.80s.
β delete-bug git:(master) node main.js
TEST_COMPONENT
β delete-bug git:(master) yarn add fuse.js
yarn add v1.12.3
warning package.json: No license field
warning No license field
[1/4] π Resolving packages...
[2/4] π Fetching packages...
[3/4] π Linking dependencies...
[4/4] π Building fresh packages...
warning No license field
success Saved 1 new dependency.
info Direct dependencies
ββ [email protected]
info All dependencies
ββ [email protected]
$ link-module-alias
link-module-alias: @components -> ./components
β¨ Done in 0.82s.
β delete-bug git:(master) β node main.js
file:///Users/xo/code/delete-bug/index.js:1
Error: Cannot find module '@components'
at Object.Module._extensions..js (internal/modules/cjs/loader.js:734:10)
PING @Rush
@OmgImAlexis I ran your steps - very helpful! .. and it looks like it's a bug in yarn ... I'll investigate it further
@OmgImAlexis it's not a permanent solution but this would help avoid this particular issue:
"scripts": {
"preinstall": "which link-module-alias && link-module-alias clean || echo",
"postinstall": "link-module-alias"
}
@OmgImAlexis the upstream bug is #5709
I added a comment to that issue thread: https://github.com/yarnpkg/yarn/issues/5709#issuecomment-453984390
@OmgImAlexis the thread seems to indicate that another workaround is not using @ in front of the aliased package name.
This happened to me a few times in the last week and it took me a while to understand that using yarn with link-module-alias was the cause of the issue. I haven't been able to reproduce it consistently, it will just happen once in a while. @Rush Is this issue only fixable on yarn's side?
@josecarneiro this patch does fix the issue.
https://github.com/Rush/link-module-alias/issues/3#issuecomment-453976562
@josecarneiro this patch does fix the issue.
I added it to my package.json and haven't been able to reproduce the issue ever since, so it seems like a plausible solution until yarn solves the underlying problem.
Thank you @OmgImAlexis and @Rush!
Well, it did happen again after running yarn upgrade, even with the fix. It appears that the upgrade command does not run the preinstall hook. Just a heads up for anyone who may be encountering the same issue.
This looks related. Possibly a bug?
https://github.com/yarnpkg/yarn/issues/2878
Is not using @ in the package name an option for you guys?
@Rush I'd prefer if we could keep using it. Any chance @/ or # would work?
I find that using Β΄@Β΄ is one of the great appeals of this module. Wanting to keep consistency between my backend codebase and my webpack-built client side app is the reason I researched this topic and consequentially found Β΄link-module-aliasΒ΄. Changing the alias is a possibility.
@Rush Having the preinstall hook do a link-module-alias clean fixes it for me when doing npm install. HOWEVER, npm update doesn't run the pre or post install hooks and will happily delete all of my files. I would usually dig in and help debug this but frankly after having this delete in progress work about 5 times now I'm a bit too pissed to be helpful. At the moment this project is completely useless if you can't use standard npm install and npm update commands without it deleting work.
I want to add to @shawncplus 's comment that this does not seem to be yarn-related at all, since it deletes files in plain npm as well.
Uh, I wasn't lucky enough to be aware of this issue before it deleted my day of work. I always forget to commit more frequently :smile:
At the moment this project is completely useless if you can't use standard
npm installandnpm updatecommands without it deleting work.
Have you tried naming your modules without the @ prefix?
"module-alias" was not working with the ESLint, so installed this one. This module worked perfectly.
And the moment I ran "yarn remove module-alias", everything in my project directory got deleted including .git
I just have just package.json and yarn.lock in directory (and the aliased directory @utils - empty).
My local commits got lost, several hours of work. Cool!
If this module has an issue, please add a big RED BOX on the npm page that this can potentially wipe the whole directory.
If this module has an issue, please add a big RED BOX on the npm page that this can potentially wipe the whole directory.
I am very sorry you've lost your work. :-( Can you share the setup that caused everything to disappear? We can then prevent doing this particular set up or at least warning against it.
@Rush, I don't have anything because everything got wiped. So, here is the explanation - no code.
- Directories - constants, config, utils, db, api.
- ESLint + Prettier config files. (.eslintrc, .prettierrc).
- jsconfig.json to make aliases work for ESLint. Had added for "module-alias" but did not work.
- And the configuration for the module as provided in the docs.
"_moduleAliases": { "@api": "./api", "@constants": "./constants", "@config": "./config", "@db": "./db", "@root": ".", "@utils": "./utils" }
ESLint was not working with "module-alias" package, so I installed this one (yours) and ESLint worked. Then the moment I ran yarn remove module-alias, everything got deleted (not even in the Trash).
I came to know that there is an issue with this module after it, if you could please add some warning with a link to this issue, it will be really helpful.
I'm ashamed that I had not pushed my work on GitHub.
BTW, I'm on Linux 18.04.2.
There's no need to be ashamed @mfaheemakhtar, you're in good company based on this thread. I second the idea of a huge warning on the NPM page for this module, or even unpublishing it, until the issue is resolved.
@seanohue @mfaheemakhtar added the warning. Let me know if you guys think it's sufficient ...
I think I will add a warning at runtime that discourages the use of modules starting with @ .
I think I will add a warning at runtime that discourages the use of modules starting with
@.
I think that's a good idea! Perhaps even throw an error if they use such an alias. I'm willing to make a PR that does this.
Thanks for being so responsive with this issue.
I'm willing to make a PR that does this.
You're very welcome to give it a first shot. Thanks!
Thanks for the quick response @Rush. Really appreciate it.
Please also consider adding the warning on the npm page and change the usage example.
I read the comments above and the issues with yarn. One way to fix it could to not store the symlinks in the node_modules folder at all.
The module can create a directory for symlinks (.aliases, or anything), and add that path to the module.paths. This way (I think), the node_modules folder will be untouched and both yarn and npm should be working fine.
I'll try this module again without the "@" now, and will not add any alias for root. I guess my .git folder was removed because I had a root entry. So, even if this happens again, at least I'll have my .git folder to recover my work.