-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add or document support for Webpack HMR #91
Comments
Hmm this is interesting. Personally I'm always using containers so I just mount an env file and run everything there. I've never really used hmr or webpack package commands. Since writing the above paragraph I install a new nest v6.1.1 application, I checked package.json for start:hmr and webpack and I think it's since been removed? In an older version hmr looked to be using a Thanks! :) |
Okay so I played around with this a bit more. Apparently I have an old version of the cli installed and at some point in the last few months Nest removed Webpack from it's I wouldn't call this a bug per-se since Nest seems to have abandoned using the HMR (I personally thought it was pretty neat compared to using So not sure the internals of this library but it seems like since everything gets compiled into a I tried messing around with it to compile and copy the Hopefully that gives you some detailed info, like I said it's probably not something you need to worry about but I think it would be cool if it worked :) |
oh I see! So it's more about the file type than the .env file. I was presuming webpack loaded it's own dotenv package and was loading from a different dir or something like that but it sounds like this is more file type related. I will try and investigate. My time is rather limited at the moment though as I'm working 2 jobs and still got to release V2! If I can find some time to investigate this in the next month or 2 I will. I'll try and get V2 published first though! After that I'll defo have a look into it! |
Your library is excellent. And I do not want to give it up. |
I looked into this and it doesn't appear to be possible to use Webpack HMR with this package. I ended up rolling my own |
@marktran, can you share your configuration file? |
|
@marktran @OLDIN what version of nest are you using? Just curious to know if you're using v6+ as HMR has been removed apparently? (not sure if that's still the case). As for the loading of configs though, yea I only built this for prod envs really, at the time. It would be possible to implement HMR support, because the ConfigService builds this statically it might be an idea to rebuild at some point. I think the issue is that the nestjs-config package, like you said, loads the files at runtime and therefore doesn't change it's dependants. I'll have a think about the best way to combat this. Currently in V2 I have implemented everything for async providers. This obviously doesn't fix the issue as these are still created at runtime and not rebuilt. I myself haven't used HMR, I'll try and find some time to play with it and try out the config package with it and see if I can find an easy "for now" solution. further to validation, it's also possible in V2 to use interfaces and classes for your config. import {TypeOrmOptions} from 'typeorm';
export default class DatabaseConfig implements TypeOrmOptions {
public type = 'mysql';
public host: string = process.env.TYPEORM_HOST;
public username: string = process.env.TYPEORM_USERNAME;
public password: string = process.env.TYPEORM_PASSWORD;
public database: string = process.env.TYPEORM_DATABASE;
public logging: boolean = process.env.TYPEORM_LOGGING === 'true';
public sync: boolean = process.env.TYPEORM_SYNCHRONIZE === 'true';
public entities: string[] = process.env.TYPEORM_ENTITIES.split(',');
public port: number = parseInt(process.env.TYPEORM_PORT);
}; |
@bashleigh I'm on the latest version of Nest. Not sure what HMR integration looked like in previous versions but it must have been pretty minimal (see: https://docs.nestjs.com/techniques/hot-reload). |
Having exact same issue here. It is unable to find config. Using version nestjs-config 1.4.0 |
Hi, I think this issue is related to dynamic path which are used to load config files.
Possible way for overcome this is use of absolute path to config dir, for e.g. Other way (im not sure, not tested) is to use webpack copy plugin, to copy config dir into correct location in "dist" Hope it helps you a little bit, |
@Isurm
No, the issue is that webpack compresses the entire project into a single js file so you no longer have |
Issue type:
nestjs-config version
1.3.21
@nestjs/common+core or other package versions
6.1.0
6.1.0
Excepted behavior
Actual behavior or outcome (for issue)
Library worked great for me on a different project. I want to use this library with a new project, but this time I am trying to use the Webpack HMR capabilities to make the app reload a lot faster. Since Nest ships with this out-of-the-box would it be nice to have some kind of recipe for supporting this flow?
I'm not familiar with the internals of this library so not sure if it's even possible to be honest. It would be really handy to be able to use this library with HMR though!
Replication/Example
Works using
yarn start
withts-node
. Doesn't work withyarn start:hmr
. The module initializes but no configuration is being read. Likely because all of the configuration is being appended into theserver.js
and is no longer in aconfig
folder.The text was updated successfully, but these errors were encountered: