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

Exports for typescript may not be correct #32

Closed
benknoble opened this issue Aug 14, 2024 · 3 comments · Fixed by #33
Closed

Exports for typescript may not be correct #32

benknoble opened this issue Aug 14, 2024 · 3 comments · Fixed by #33

Comments

@benknoble
Copy link

Compiler Error

src/main.ts:5:19 - error TS7016: Could not find a declaration file for module 'piscina-locks'. '$HOME/code/temp/vue-project/node_modules/piscina-locks/dist/esm-wrapper.mjs' implicitly has an 'any' type.
  There are types at '$HOME/code/temp/vue-project/node_modules/piscina-locks/dist/lib/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'piscina-locks' library may need to update its package.json or typings.

5 import locks from 'piscina-locks'

Possible solution

It looks like the types line in package.json might also need to be in the exports spec, but I'm out of my depth here.

Workaround

Use // @ts-expect-error to ignore this particular error until this issue is resolved.

MRE

# yarn create vue
# some prompts translated from French, so may not line up exactly with what you see
✔ Name of project: … vue-project
✔ Add TypeScript? … Yes
✔ Add JSX support? … No
✔ Add Vue Router…? … No
✔ Add Pinia? … Yes
✔ Add Vitest? … Yes
✔ Add e2e test library? › No
✔ Add ESLint? … Yes
✔ Add Prettier? … Yes
✔ Add the extension Vue DevTools 7? (experimental) … No

# cd vue-project
# yarn add -D piscina-locks
# edit src/main.ts
# nl !$
     1	import './assets/main.css'
      	
     2	import { createApp } from 'vue'
     3	import { createPinia } from 'pinia'
     4	import locks from 'piscina-locks'
     5	import App from './App.vue'
      	
     6	const app = createApp(App)
      	
     7	app.use(createPinia())
      	
     8	app.mount('#app')
# yarn build
# ^--- this is where the compiler error shows up

Here are the various tsconfig files added to the MRE, in case that helps:

# tsconfig.app.json
     1	{
     2	  "extends": "@vue/tsconfig/tsconfig.dom.json",
     3	  "include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
     4	  "exclude": ["src/**/__tests__/*"],
     5	  "compilerOptions": {
     6	    "composite": true,
     7	    "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
      	
     8	    "baseUrl": ".",
     9	    "paths": {
    10	      "@/*": ["./src/*"]
    11	    }
    12	  }
    13	}
# tsconfig.json
     1	{
     2	  "files": [],
     3	  "references": [
     4	    {
     5	      "path": "./tsconfig.node.json"
     6	    },
     7	    {
     8	      "path": "./tsconfig.app.json"
     9	    },
    10	    {
    11	      "path": "./tsconfig.vitest.json"
    12	    }
    13	  ]
    14	}
# tsconfig.node.json
     1	{
     2	  "extends": "@tsconfig/node20/tsconfig.json",
     3	  "include": [
     4	    "vite.config.*",
     5	    "vitest.config.*",
     6	    "cypress.config.*",
     7	    "nightwatch.conf.*",
     8	    "playwright.config.*"
     9	  ],
    10	  "compilerOptions": {
    11	    "composite": true,
    12	    "noEmit": true,
    13	    "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
      	
    14	    "module": "ESNext",
    15	    "moduleResolution": "Bundler",
    16	    "types": ["node"]
    17	  }
    18	}
# tsconfig.vitest.json
     1	{
     2	  "extends": "./tsconfig.app.json",
     3	  "exclude": [],
     4	  "compilerOptions": {
     5	    "composite": true,
     6	    "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.vitest.tsbuildinfo",
      	
     7	    "lib": [],
     8	    "types": ["node", "jsdom"]
     9	  }
    10	}
@benknoble
Copy link
Author

@bienzaaron the fix in #33 didn't work for me: when I do the same repro as in the original post, I get the following now with yarn build:

# yarn build
yarn run v1.22.22
$ run-p type-check "build-only {@}" --
$ vue-tsc --build
$ vite build
vite v6.0.6 building for production...
✓ 2 modules transformed.
x Build failed in 72ms
error during build:
[commonjs--resolver] Failed to resolve entry for package "piscina-locks". The package may have incorrect main/module/exports specified in its package.json.
    at packageEntryFailure (file:///private/tmp/vue-project/node_modules/vite/dist/node/chunks/dep-0AosnpPU.js:16462:15)
    at resolvePackageEntry (file:///private/tmp/vue-project/node_modules/vite/dist/node/chunks/dep-0AosnpPU.js:16459:3)
    at tryNodeResolve (file:///private/tmp/vue-project/node_modules/vite/dist/node/chunks/dep-0AosnpPU.js:16324:18)
    at Object.resolveId (file:///private/tmp/vue-project/node_modules/vite/dist/node/chunks/dep-0AosnpPU.js:16109:19)
    at Object.handler (file:///private/tmp/vue-project/node_modules/vite/dist/node/chunks/dep-0AosnpPU.js:51072:15)
    at file:///private/tmp/vue-project/node_modules/rollup/dist/es/shared/node-entry.js:20874:40
    at async PluginDriver.hookFirstAndGetPlugin (file:///private/tmp/vue-project/node_modules/rollup/dist/es/shared/node-entry.js:20774:28)
    at async resolveId (file:///private/tmp/vue-project/node_modules/rollup/dist/es/shared/node-entry.js:19378:26)
    at async ModuleLoader.resolveId (file:///private/tmp/vue-project/node_modules/rollup/dist/es/shared/node-entry.js:19807:15)
    at async Object.resolveId (file:///private/tmp/vue-project/node_modules/vite/dist/node/chunks/dep-0AosnpPU.js:5658:10)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
ERROR: "build-only" exited with 1.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I get something similar with yarn 4.1.1 on real project.

@bienzaaron
Copy link
Contributor

@benknoble should be good now on 3.1.1

@benknoble
Copy link
Author

Looks like #72 is working for me so far, thanks!

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

Successfully merging a pull request may close this issue.

2 participants