Tag Archives: Critical dependency

How to Solve Critical dependency: the request of a dependency is an expression?

In some cases, the following errors will occur when using the ruoyi background:

According to the prompt, we can find that the main code causing this problem is the following paragraph:

export const loadView = (view) => { 
  return () => import(`@/views/${view}`)
}

Global search node_ Modules we can see that this problem is a warning given by the 224 line of lib/dependencies/contextdependencyhelpers. JS of webpack

Then, relevant questions can be found in the official issues

However, it seems that the government has not given a solution (or maybe I have not found it). Maybe the government does not agree with the introduction of Import ('@/views/${view}')

We can also try to introduce it in a different way, for example:

export const loadView = (view) => { 
  return () => Promise.resolve(require(`@/views/${view}`).default)
}

In this way, the component can be loaded asynchronously, and no exception will be reported by webpack , Terminal looks much more comfortable