loopbackio / loopback-next

LoopBack makes it easy to build modern API applications that require complex integrations.
https://loopback.io
Other
4.95k stars 1.07k forks source link

Creating repository is failing with error 'events.js:187 throw er; // Unhandled 'error' event' #4156

Closed Oliverq755 closed 4 years ago

Oliverq755 commented 4 years ago

Steps to reproduce

  1. clone a new project or download the zip of loopback project
  2. extract the loopback project at your desire location
  3. install the node modules using npm install
  4. create a model for your project using lb4 model
  5. create a repository for your existing datasource using lb4 repository

I downloaded the zip folder of my project and extracted to my location. I installed all the required nodemodules and started the project. It got successfully run. Now I tried to create a new model for my project using the code lb4 model which was also successful. Now I have already datasource setup and want new repository for that datasource. I started to create new repository using lb4 repository but it thows error events.js:187 throw er; // Unhandled 'error' event ^ Error: Cannot load /home/ecas0002/Repos/demo-backendcode/src/datasources/update.datasource.config.json: ENOENT: no such file or directory, open '/home/ecas0002/Repos/demo-backendcode/src/datasources/update.datasource.config.json'

Current Behavior

events.js:187 throw er; // Unhandled 'error' event ^ Error: Cannot load /home/ecas0002/Repos/demo-backendcode/src/datasources/update.datasource.config.json: ENOENT: no such file or directory, open '/home/ecas0002/Repos/demo-backendcode/src/datasources/update.datasource.config.json'

Expected Behavior

It should normally create and repository by allowing me to choose datasource and model.

Additional information

events.js:187 throw er; // Unhandled 'error' event ^ Error: Cannot load /home/ecas0002/Repos/demo-backendcode/src/datasources/update.datasource.config.json: ENOENT: no such file or directory, open '/home/ecas0002/Repos/demo-backendcode/src/datasources/update.datasource.config.json'

See Reporting Issues for more tips on writing good issues

bajtos commented 4 years ago

create a repository for your existing datasource

How is your datasource configured? Do you have src/datasources/update.datasource.config.json present in your project? Maybe you have src/datasources/update.datasource.json instead?

We have recently changed the file names of datasource JSON files to accommodate breaking changes introduced by TypeScript version 3.7.

@raymondfeng Do we have any migration guide showing our users how to deal with this change?

bajtos commented 4 years ago

Here is the pull request that introduced the change: https://github.com/strongloop/loopback-next/pull/4060

Oliverq755 commented 4 years ago

@bajtos Yes, this is causing because of the latest changes to accommodate breaking changes introduced by TypeScript version 3.7. I uninstalled the current version and installed 1.21.3 version and it worked. I will try the migration later. Is there any migration steps included?

achrinza commented 4 years ago

@Oliverq755 I don't think there's an official migration documented yet, but renaming all instances of *.datasource.json to *.datasource.config.json and renaming references to the files will fix the issue when using typescript@~3.7.0.

Updating the @loopback/cli to the latest version will fix the issue for future generated datasources.

Similar: #4173, #4119

Oliverq755 commented 4 years ago

@Oliverq755 I don't think there's an official migration documented yet, but renaming all instances of *.datasource.json to *.datasource.config.json and renaming references to the files will fix the issue when using typescript@~3.7.0.

Updating the @loopback/cli to the latest version will fix the issue for future generated datasources.

Similar: #4173, #4119

@achrinza Thanks for the reply, I downgraded my loopback version @1.21.3 which fixes the issue. However, the latest @loopback/cli version fixes the future generation of data sources, but what if we are using the old version generated applications. I don't think it's a proper way (renaming all instances of *.datasource.json to *.datasource.config.json and renaming references to the files) to fix this issue. There should be auto migration which could be done when user do npm install.

dougal83 commented 4 years ago

I don't think it's a proper way (renaming all instances of *.datasource.json to *.datasource.config.json and renaming references to the files) to fix this issue. There should be auto migration which could be done when user do npm install.

Might not be proper but it seems to work. For those with plentiful datasources though, I think that you can open the project in a tool like VsCode with import path correction enabled ("typescript.updateImportsOnFileMove.enabled": "always",) and bulk rename the files using a script or shareware tool. Doesn't warrant addition to install script for a one time change. Maybe the change should be considered breaking if it is causing the error.

bajtos commented 4 years ago

There should be auto migration which could be done when user do npm install.

I agree that a migration tool would be great. I am don't think it can be invoked by npm install, but that's an implementation detail.

The bigger problem is that we don't have enough bandwidth to implement such tool. It requires a non-trivial amount of work with little pay-off, because most users will run it only once.

Personally, I would start with improving the way how we are communicating breaking changes and make the migration guides easier to find.

In https://github.com/strongloop/loopback-next/pull/4080, we introduced lb4 update command, it think it provides a good place where to educate users about changes they need to make after upgrading to newer version of LB4 dependencies. It can implement proper auto-migration too, but as I said, that may require more work than we are willing to invest.

@dougal83 would you be interested in implementing & contributing such feature yourself?

agnes512 commented 4 years ago

Opened an issue https://github.com/strongloop/loopback-next/issues/4864 for improving the breaking change message announcement. Closing the issue as the content might be misleading. Feel free to join discussion there.