apollo icon indicating copy to clipboard operation
apollo copied to clipboard

build with nuxt3 not find tslib

Open NaCoLiu opened this issue 1 year ago • 12 comments

Environment

Nuxi 3.5.3                                                                                                                    7:32:45 PM
                                                                                                                              7:32:45 PM
RootDir: /Users/naco/Documents/retain                                                                                         7:32:45 PM
Nuxt project info: (copied to clipboard)                                                                                      7:32:45 PM

------------------------------
- Operating System: Darwin
- Node Version:     v18.16.0
- Nuxt Version:     3.5.3
- Nitro Version:    2.4.1
- Package Manager:  [email protected]
- Builder:          vite
- User Config:      app, devtools, srcDir, modules, imports, pinia, alias, apollo
- Runtime Modules:  @nuxtjs/[email protected], @pinia/[email protected]
- Build Modules:    -
------------------------------

👉 Report an issue: https://github.com/nuxt/nuxt/issues/new                                                                   7:32:45 PM

👉 Suggest an improvement: https://github.com/nuxt/nuxt/discussions/new

👉 Read documentation: https://nuxt.com

Describe the bug

naco@NaCo retain % node .output/server/index.mjs    
Listening http://[::]:3000
[nuxt] [request error] [unhandled] [500] Cannot find module '/Users/naco/Documents/retain/.output/server/node_modules/tslib/modules/index.js' imported from /Users/naco/Documents/retain/.output/server/chunks/app/server.mjs
Did you mean to import tslib/tslib.js?
  at new NodeError (node:internal/errors:399:5)  
  at finalizeResolution (node:internal/modules/esm/resolve:326:11)  
  at moduleResolve (node:internal/modules/esm/resolve:945:10)  
  at defaultResolve (node:internal/modules/esm/resolve:1153:11)  
  at nextResolve (node:internal/modules/esm/loader:163:28)  
  at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)  
  at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)  
  at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)  
  at link (node:internal/modules/esm/module_job:76:36)

Expected behaviour

nuxt.config.ts

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  app: {
    head: {
      charset: 'utf-8',
      viewport: 'width=device-width, initial-scale=1',
    }
  },
  devtools: { enabled: true },
  srcDir:"./src",
  modules: ['@nuxtjs/apollo','@pinia/nuxt'],
  imports: {
    dirs: ['./store'],
  },
  pinia: {
    autoImports: ['defineStore', 'acceptHMRUpdate','storeToRefs'],
  },
  alias: {
    tslib: 'tslib'
  },
  apollo: {
    clients: {
      default: {
        httpEndpoint: 'https://api.nco.im/graphql'
      }
    },
  },
})

Reproduction

No response

Additional context

No response

Logs

No response

NaCoLiu avatar Jun 20 '23 11:06 NaCoLiu

Likely due to this change to tslib exports, you can override the version to one that works

PNPM

{
 "pnpm": {
    "overrides": {
      "tslib": "2.5.1"
    }
  }
}

Yarn

{
  "resolutions": {
    "tslib": "2.5.1"
  }
}

slavanossar avatar Jun 20 '23 12:06 slavanossar

@slavanossar thx bro.

NaCoLiu avatar Jun 20 '23 12:06 NaCoLiu

@NaCoLiu I think leave this issue open, this module might need to be updated to use new exports from tslib so the issue needs to be tracked

slavanossar avatar Jun 20 '23 12:06 slavanossar

@slavanossar any resolution for npm?

oosame avatar Jun 22 '23 08:06 oosame

@oosame you can try pinning the version by adding the required version as a dependency

npm install [email protected] --save-dev

slavanossar avatar Jun 22 '23 08:06 slavanossar

@oosame you can try pinning the version by adding the required version as a dependency

npm install [email protected] --save-dev

thx bro.

markhacd avatar Jun 29 '23 03:06 markhacd

Also need to check that package.json has "type": "module"

FamilyMan avatar Jul 03 '23 15:07 FamilyMan

@slavanossar any resolution for npm?

{
	"overrides": {
		"tslib": "2.5.1"
	}
}

iamandrewluca avatar Jul 12 '23 11:07 iamandrewluca

Related issues:

  • https://github.com/nuxt/nuxt/issues/19265
  • https://github.com/vueuse/motion/issues/102
  • https://github.com/nuxt-modules/apollo/issues/516

iamandrewluca avatar Jul 12 '23 11:07 iamandrewluca

Any updates on this? It'd be nice if this gets fixed in v5 and we could use the latest version tslib, since some other libraries need it.

Sina-Afsharmanesh avatar Oct 06 '23 15:10 Sina-Afsharmanesh

@Sina-Afsharmanesh check one of these solutions. Both should work.

https://github.com/nuxt/nuxt/issues/19265#issuecomment-1702014262

iamandrewluca avatar Oct 06 '23 15:10 iamandrewluca

just add to nuxt config

 build: {
    transpile: ['tslib']
  }

Xanndr-exe avatar Nov 29 '23 20:11 Xanndr-exe