question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[nuxt] [request error] Directory import '...\.output\server\node_modules\@apollo\client\core' is not supported resolving ES modul es imported from ...\.output\server\chunks\server.mjs Did you mean to import @apollo/client/core/index.js?

See original GitHub issue

Environment

Nuxt CLI v3.0.0-rc.3 14:35:02 RootDir: C:\Users\Ilya\Desktop\nuxt-app 14:35:06 Nuxt project info: 14:35:06


  • Operating System: Windows_NT
  • Node Version: v16.15.0
  • Nuxt Version: 3.0.0-rc.3
  • Package Manager: yarn@1.22.15
  • Builder: vite
  • User Config: ssr
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://github.com/loremru/bug-reproduction

https://stackblitz.com/edit/github-pskqpw?file=package.json,nuxt.config.ts,app.vue,package-lock.json,graphql%2Fquery.js

yarn build yarn start

Describe the bug

Apollo Client doesnt work in a BUILD with SSR: true. In DEV or SSR off its ok.

[nuxt] [request error] Directory import ‘….output\server\node_modules@apollo\client\core’ is not supported resolving ES modul es imported from ….output\server\chunks\server.mjs Did you mean to import @apollo/client/core/index.js?

image

https://stackblitz.com/edit/github-pskqpw?file=package.json,nuxt.config.ts,app.vue,package-lock.json,graphql%2Fquery.js

yarn build yarn start

Additional context

No response

Logs

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

6reactions
mekedroncommented, May 23, 2022

Hello everybody! You need to transpile all the modules which use @apollo/client. So if you use @vue/apollo-composable then you need to add this module to transpile section either.

defineNuxtConfig({
 build: {
   transpile: ['@apollo/client', '@vue/apollo-composable']
 }
})

Also you can transpile the modules only during building:

const lifecycle = process.env.npm_lifecycle_event

defineNuxtConfig({
  build: {
    transpile: lifecycle === 'build' || lifecycle === 'generate' ? ['@apollo/client', '@vue/apollo-composable'] : [],
  }
})
3reactions
manniLcommented, Aug 24, 2022

UPDATE: See https://github.com/nuxt/framework/issues/5023#issuecomment-1134698184 for the solution


Apollo should work fine on both, server and client side. But it likely must be transpiled.

Add '@apollo/client' and 'ts-invariant/process' to your transpile array in the nuxt.config.js/.ts

example:

defineNuxtConfig({
  build: {
    transpile: ['@apollo/client', 'ts-invariant/process']
  }
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

'Directory import is not supported resolving ES modules ...
With ES6 modules you can not (yet?) import directories. Your import should look like this: import database from "./database/index.js".
Read more >
Assets directory
The assets directory contains your un-compiled assets such as Stylus or Sass files, images, or fonts. Images. Inside your vue templates, if you...
Read more >
[nuxt] [request error] require is not defined in es module ...
Im trying to unse lighGallery inside a Vue Component with Nuxt 3 rc8 First i got a error that it is not possible...
Read more >
Directory import '[~]/node_modules/firebase/app' is not ...
Directory import '[~]/node_modules/firebase/app' is not supported resolving ES modules imported from /[~] Did you mean to import firebase/app/dist/index.cjs.js?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found