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

Use relative path to dynamic import #28

Closed
rtritto opened this issue Oct 8, 2024 · 4 comments
Closed

Use relative path to dynamic import #28

rtritto opened this issue Oct 8, 2024 · 4 comments

Comments

@rtritto
Copy link
Contributor

rtritto commented Oct 8, 2024

[vite] warning:
C:/test-elysia-autoload/node_modules/elysia-autoload/dist/index.js
102|    for await (const filePath of sortByNestedParams(files)) {
103|      const fullPath = path.join(directoryPath, filePath);
104|      const file = await import(fullPath);
   |                                ^^^^^^^^
105|      const importName = typeof getImportName === "string" ? getImportName : getImportName(file);
106|      if (!file[importName] && options?.skipImportErrors) continue;
The above dynamic import cannot be analyzed by Vite.
See https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#limitations for supported dynamic import formats. If this is intended to be left as-is, you can use the /* @vite-ignore */ comment inside the import() call to suppress this warning.

  Plugin: vite:import-analysis
  File: C:/test-elysia-autoload/node_modules/elysia-autoload/dist/index.js

Fix

The ignore comment can be safely added.

const file = await import(fullPath);

- const file = await import(fullPath);
+ const file = await import(/* @vite-ignore */ fullPath);

Infos

[email protected]

Maybe fix #24

@rtritto
Copy link
Contributor Author

rtritto commented Oct 13, 2024

This error occurs only if elysia-autoload isn't transpiled

@rtritto rtritto closed this as completed Oct 13, 2024
@kravetsone
Copy link
Owner

This error occurs only if elysia-autoload isn't transpiled

Vite for browser shouldn't transpile elysia-autoload)

@rtritto
Copy link
Contributor Author

rtritto commented Oct 13, 2024

So it's better to add /* @vite-ignore */ anyway?

https://github.com/brillout/import/blob/ba848455442484eb258aaa2d9864d4848e4ed0fb/index.ts#L4-L34
Similar usage with @brillout/import: dynamic import + webpack use case with /*webpackIgnore: true*/ (Idk why /* @vite-ignore */ is missing if @brillout/import is used under vike (vite))

@rtritto
Copy link
Contributor Author

rtritto commented Oct 14, 2024

The vite:import-analysis should ignore dependencies, so the @vite-ignore and webpackIgnore can be omitted.

@rtritto rtritto closed this as not planned Won't fix, can't repro, duplicate, stale Oct 14, 2024
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

No branches or pull requests

2 participants