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

An issue with Pinia on Deno #20375

Open
bitsnaps opened this issue Sep 4, 2023 · 3 comments
Open

An issue with Pinia on Deno #20375

bitsnaps opened this issue Sep 4, 2023 · 3 comments
Labels
bug Something isn't working correctly node compat

Comments

@bitsnaps
Copy link

bitsnaps commented Sep 4, 2023

Hi,

1- After following the example of Deno with Vue, I attempted to place every dependency in deps.ts as per conventional practice. Initially, the defineConfig function from vite was added, and everything seemed to be working fine at this stage.

File: deps.ts:

export { defineConfig } from 'npm:vite@^4.3.9'

File: vite.config.mts:

import { defineConfig } from './deps.ts'
import vue from 'npm:@vitejs/plugin-vue@^4.2.3'
import 'npm:vue@^3.3.4'
import 'npm:vue-router@4'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
})

At this point, the app runs fine. However, when attempting to use the vue function from the vite-vue plugin in the second step, it doesn't seem to be possible to do it the same way.

File: deps.ts:

export { vue } from 'npm:@vitejs/plugin-vue@^4.2.3'
// or
// export * from 'npm:@vitejs/plugin-vue@^4.2.3'

File: vite.config.mts:

import { defineConfig } from './deps.ts'
import { vue } from './deps.ts' // is not recognized

import 'npm:vue@^3.3.4'
import 'npm:vue-router@4'

export default defineConfig({
  plugins: [vue()],
})

How can I export all npm packages to deps.ts? What about npm:vue@^3.3.4 and npm:vue-router@4?

2- Keeping the dependencies in the vite.config.mts file, I wanted to add pinia. Here is what I added to deps.ts:

export { createPinia, defineStore } from 'npm:pinia@2.1.6'

File: main.ts:

import { createPinia } from '../deps.ts'
// other imports

const app = createApp(App)
app.use(createPinia())
app.mount('#app')

The syntax seems to be fine according to vscode's inspection, but now I'm getting a weird error:

[plugin:vite:import-analysis] Failed to resolve import "npm:vite@^4.3.9" from "deps.ts". Does the file exist?
/path/to/deps.ts:2:29
1  |  export { defineConfig } from "npm:vite@^4.3.9";
   |                                ^
2  |  export { createPinia, defineStore } from "npm:pinia@2.1.6";
3 

Is this error related to how Deno resolves dependencies? Can we just import the full direct link without using npm?

@bitsnaps
Copy link
Author

bitsnaps commented Oct 8, 2024

@bartlomieju, as far as I know Deno projects generally don't require a JS bundler, which means we can rewrite this example without Vite. Given that pinia is not built on the Node API per its creator, we could consider closing this issue before releasing Deno v2, right?

@marvinhagemeister
Copy link
Contributor

The error is thrown by the transpilation pipeline in vite. Before the config file is executed, it is bundled with esbuild. But esbuild isn't aware of Deno-resolution, therefore it throws an error. In other words: Using Deno-specific resolution in vite.config.ts is not possible at the moment.

We have a plugin for vite here https://github.com/denoland/deno-vite-plugin that teaches vite Deno-specific resolution everywhere else though.

@bitsnaps
Copy link
Author

bitsnaps commented Oct 9, 2024

The error is thrown by the transpilation pipeline in vite. Before the config file is executed, it is bundled with esbuild. But esbuild isn't aware of Deno-resolution, therefore it throws an error. In other words: Using Deno-specific resolution in vite.config.ts is not possible at the moment.

So, we can technically use a different bundler which doesn't rely on esbuild (such as Farm AFAIK) to fix that issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly node compat
Projects
None yet
Development

No branches or pull requests

3 participants