Yevhenii Kamenskyi
Yevhenii Kamenskyi

Reputation: 69

Vite Vue Npm link exports{*/dist} How to fix "Failed to resolve"

How to fix "Failed to resolve"?

If you have a Vue3 app that uses local packages imported via npm link with symbolic links, and you encounter the following error:

12:29:14 PM [vite] Pre-transform error: Failed to resolve import "my-package/socket" from "src/main.ts". Does the file exist?

or

Error: The following dependencies are imported but could not be resolved:

  my-package/socket (imported by 

And the package files in the package.json exports look like:

{
"name": "my-package",
"exports": {
    "./*": {
      "types": "./dist/*.d.ts",
      "default": "./dist/*.js"
    }
  }
}

Workaround Solution

vite.config.ts

// https://vitejs.dev/config/
export default defineConfig({
  ...
  resolve: {
    alias: {
      'my-package': fileURLToPath(new URL('node_modules/my-package/dist', import.meta.url)),
      ...
  }
})

Upvotes: 0

Views: 210

Answers (0)

Related Questions