I'm trying to migrate my Angular Universal project from Angular v5 to v6
I've got a service where I use fs
to load the translation on the server side. Everything works well with Angular v5.
With Angular v6, when I run npm run start
aka ng serve --proxy-config proxy.conf.json
I face the following error
ERROR in
./src/providers/core/translate/translate-universal-loader.service.ts
Module not found: Error: Can't resolve 'fs' in
'/Users/me/Documents/projects/myproject/src/providers/core/translate'
In my service I declare fs
like the following:
declare var require: any;
const fs = require('fs');
I also tried to declare it like following, but didn't help
import * as fs from 'fs';
To tell webpack to ignore fs I tried to add the following in my webpack.server.config.js
without success
node: {
fs: 'empty'
}
also tried with a webpack plugin, wasn't successful neither
new webpack.IgnorePlugin(/fs/)
but actually it's maybe not the config use by ng serve
but I don't know if I could still eject the configuration with v6?
anyone has got an idea?
UPDATE
If I declare fs as any
it solves the problem for ng serve
but unfortunately it will not work on the server side after npm run build:ssr
and run npm run serve
. On the server side I will then face the following error
ERROR ReferenceError: fs is not defined
p.s.: my project follows https://github.com/angular/universal-starter structure, config and dependencies
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…