Greentube / localize-router

An implementation of routes localisation for Angular
MIT License
193 stars 93 forks source link

TypeError: fs.readFileSync is not a function, Cannot find name 'require'. #46

Closed brada1703 closed 7 years ago

brada1703 commented 7 years ago

Hi,

I'm trying to load localize-router and am having the following error:

"Cannot find name 'require'."

In order to fix this, I used declare var require: any;

However, then I am still stuck with the following error:

"TypeError: fs.readFileSync is not a function"

screen shot 2017-04-25 at 10 32 44 am

One thing I did was to combine app.browser.module.ts and app.node.module.ts into one app.module.ts. I'm not sure if this could be the problem.

Another possible problem is that I'm using Angular4.

Again, I'm really not sure where this is coming from. If you guys have any ideas, I'd really appreciate it.

Thanks!

meeroslav commented 7 years ago

Hi @brada1703, usign Angular 4 should not be the problem if you are using the latest version of localize-router. Mixing browser and node module on the other hand would most likely cause some issues. Based on your error message, Typescipt is complaining about fs which is node file system library and would not work in browser. Same thing applies for require.

Why did you combine those two in the first place?

brada1703 commented 7 years ago

Hi @meeroslav

Thanks for your quick reply.

I combined the two to avoid repeating all of my imports and to keep the routes in one location. Additionally, since the "export class AppModule { }" is the same, I didn't think it would hurt.

I have now separated the two into their respective files and it now works!

Great advice! Thanks 👍

(In case someone else has this problem in the future, When you separate the files, you will get an error unless you change the "client.ts" (or in my case, it was "main.ts" file from import {AppModule} from './app/app.module' to import { AppModule } from './app/';)