简体   繁体   中英

How to require a different node module client-side?

I'm trying to internationalize an isomorphic react app using i18next . While getting it to work server-side was no big deal, it fails client-side, telling me fs.readFile is not a function . As far as I understand, in order to use i18next in the browser (with browserify), you need to require i18next-client , which means, that I would need to require a different node module on the server than on the client. After some research I still have absolutely no idea how to get this done and am asking myself if I understand something completely wrong here?

您可以检查process.browser使用Browserify时只被定义浏览器端。

var i18n = process.browser ? require('i18next-client') : require('i18next');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM