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
Error: Module not found: Error: Can't resolve 'fs' #8272
Comments
|
yes, i have the same issue when i run |
|
Same here |
|
@lughino can you show the offending code? are you trying to use nodes fs module? |
|
@deebloo sure! import { Inject, Injectable, PLATFORM_ID } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
import { readFile } from 'fs';
import { join } from 'path';
import { IEnvConfig } from './env.config';
import { RestApiClient } from '../rest-api-client/rest-api-client';
@Injectable()
export class ConfigService {
private envConfig: IEnvConfig;
constructor(@Inject(PLATFORM_ID) private platformId: Object, private restApiClient: RestApiClient) {
}
load() {
if (isPlatformBrowser(this.platformId)) {
return this.loadUsingHttpClient();
} else {
return this.loadFromFileSystem();
}
}
private loadUsingHttpClient() {
return new Promise((resolve, reject) => {
const DIVISOR = 1000;
const cacheBuster = Math.round(new Date().getTime() / DIVISOR);
this.restApiClient.get(`app/config/env.json?v=${cacheBuster}`)
.catch(error => {
reject(`Error loading env.json file: ${JSON.stringify(error)}`);
return 'Server error';
})
.subscribe(envConfig => {
this.envConfig = envConfig as IEnvConfig;
resolve();
});
});
}
private loadFromFileSystem() {
return new Promise((resolve) => {
const DIST_FOLDER = join(process.cwd(), 'dist');
readFile(`${DIST_FOLDER}/browser/app/config/env.json`, 'utf8', (err, data) => {
if (err) {
return this.handleError(err);
}
this.envConfig = JSON.parse(data);
resolve();
});
}).catch(this.handleError);
}
private handleError(err) {
console.log(`Error loading env.json file: ${JSON.stringify(err)}`);
return 'Server error';
}
get (): IEnvConfig {
return this.envConfig;
}
}Before upgrading to the new cli / angular 5, it was working fine. |
|
Angular apps such as the ones Angular CLI creates are browser apps. Even if it worked before this was never a supported feature. I'm sorry but this is working as intended :/ |
|
@filipesilva thanks for the feedback, but Angular applications are supposed to work in a "universal" context, so using different strategy between client and server is reasonable. |
|
I fully agree with @lughino |
|
Closing this issue doesn't make any sense; why it's angular "Universal" if it's suppose to run on browsers only .. @filipesilva |
|
The app in this issue didn't seem to be a universal app. We have some support for universal apps but it requires custom setup as shown in https://github.com/angular/angular-cli/wiki/stories-universal-rendering. Unit tests are also not Universal apps either. Maybe @MarkPieszak or @Toxicable can direct you to some more information about what node facilities are available with the Universal setup, but as for as the browser apps are concerned there is no |
|
I had the same issue, when upgrading one of my angular 4.0 universal app to angular 5. |
|
I'm confused. How the hell am I supposed to use
Now my tests are failing: @filipesilva @Toxicable what do you guys recommend? I'm clueless. ): |
|
@alfaproject Try adding Let me know if that solves your issue |
|
@Toxicable that's what I have already. ): |
|
@alfaproject do you override that anywhere with a |
|
Then how are we supposed to use Angular with Electron to make desktop apps if we cannot use node modules like fs, os etc? |
|
@Toxicable nope, but it doesn't matter anymore, I guess. The dependency I was having issues with removed support for universal. \: |
|
You can fix it, just add to the "package.json" |
|
@pakhuta you save my times, thanks |
@pakhuta |
|
it work for me to add the code after devdependencies "browser": { |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug Report or Feature Request (mark with an
x)Versions.
Angular CLI: 1.5.0-rc.6
Node: 6.11.0
OS: darwin x64
Angular: 5.0.0-rc.9
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router
@angular/cli: 1.5.0-rc.6
@angular-devkit/build-optimizer: 0.0.31
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.34
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.0-rc.6
@schematics/angular: 0.0.49
typescript: 2.6.1
webpack: 3.8.1
Repro steps.
Put some node module inside one file
ng test --code-coverage --watch=falseThe log given by the failure.
Error: Module not found: Error: Can't resolve 'fs' in '/Users/luca/src/app/core/service/config'
Desired functionality.
Prior to update the new version of angular cli and angular 5 the error didn't happen.
When I build or serve, no errors.
Fix this functionality before release the final version.
The text was updated successfully, but these errors were encountered: