Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Critical dependency: the request of a dependency is an expression #88

Closed
wmm387 opened this issue Apr 21, 2020 · 9 comments
Closed

Critical dependency: the request of a dependency is an expression #88

wmm387 opened this issue Apr 21, 2020 · 9 comments

Comments

@wmm387
Copy link

wmm387 commented Apr 21, 2020

in vue-router

  {
    path: '/',
    name: 'home',
    component: () => import('@/views/home/index'),
    meta: {
      title: 'Home'
    }
  }

error: Critical dependency: the request of a dependency is an expression;
webpack-internal:///./node_modules/vue-router/dist/vue-router.esm.js:17 [vue-router] Failed to resolve async component default: Error: Cannot find module '@/views/home/index'

Rolling back and locking into 2.3.0 resolves the issue.

@haiweilian
Copy link

I also have this problem.

@imzyxwvu
Copy link

Me too. Downgrading fixes this.

@CiklopLT
Copy link

Same here, should be downgraded to 2.3.0

ZauberNerd added a commit to xing/hops that referenced this issue Apr 21, 2020
@KnisterPeter
Copy link

The created output here is something like this:

Promise.resolve('prefix-${var}').then(s => require(s))

If this is check by webpack, it results in unmatched dynamic imports.
Webpack could understand require('prefix-${var}') but not require(s)

The fix for #84 need to be reverted and fixed in another way.

@ljharb
Copy link
Collaborator

ljharb commented Apr 21, 2020

cc @nicolo-ribaudo we may have to revert to the original, but still evaluate the result twice so as to evaluate it sync?

@ljharb
Copy link
Collaborator

ljharb commented Apr 21, 2020

@wmm387 @KnisterPeter this plugin is for node, not for webpack - we have https://github.com/airbnb/babel-plugin-dynamic-import-webpack for webpack 1 and 2, and webpack 3+ understands this syntax natively.

@KnisterPeter
Copy link

@ljharb Thanks for the hint

@nicolo-ribaudo
Copy link
Contributor

cc @nicolo-ribaudo we may have to revert to the original, but still evaluate the result twice so as to evaluate it sync?

Evaluating twice is worse than evaluating asynchronously. Also, it would bring back the bug that originally led to that PR (yield or await inside import arguments).

If the dynamic import argument is a single StringLiteral, we could transpile it to

Promise.resolve().then(s => require("./module"))

in more complex cases where it would be observable, I think that it is better to do the correct thing rather than trying to adapt the output to webpack, which doesn't need this plugin in the first place.

@ljharb
Copy link
Collaborator

ljharb commented Apr 21, 2020

That seems totally reasonable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants