Skip to content

How to load namespaces from node_modules? #572

Answered by aralroca
coderjib asked this question in Q&A
Discussion options

You must be logged in to vote

I think this has to do with how Webpack works to resolve dynamic imports. It needs to know in advance the path to create the necessary chunks. If the path is dynamic, Webpack does not know which chunks to create, and I guess the problem comes from here.

Something like this:

function loadLocaleFrom(lang, ns) {
 const path = someCondition ? './some-path' : '/another-path'
 return import(`{path}/${lang}/${ns}.json`).then((m) => m.default),
}

Webpack don't know the path in advance. So maybe it helps to change it to something like:

function loadLocaleFrom(lang, ns) {
 if(someCondition) return  import(`./some-path/${lang}/${ns}.json`).then((m) => m.default)
 return  import(`./another-path/${lang}/

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by aralroca
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #560 on April 08, 2021 12:18.