antfu-collective / vitesse

πŸ• Opinionated Vite + Vue Starter Template
https://vitesse.netlify.app/
MIT License
8.82k stars 931 forks source link

Weird error everytime I use this regex #271

Closed 8bu closed 2 years ago

8bu commented 2 years ago

PLEASE READ: I originally made this template for myself to mocking up apps quicker. I am glad to see you are willing to give it a try! Before your open the issue, please make sure you are reporting bugs in the template itself. I am NOT creating this template to solve the problems you faced in your project, please use Vue or Vite's discord server to ask questions (or it might be closed directly without further notice). Thank you.

Describe the bug/issue Reproduce repo: https://github.com/8bu/vite-regex-error/blob/00bd134cae71583d9bcefae51d70ce559f534384/src/components/PageLink.vue#L5

const isHttp = computed(() => /^(https?:\/\/|\/\/)/.test(props.to))

Everytime I use this regex my app crash & throw error. This is really weird & I've tried to reproduce with pnpm create vite template and it got no error. Next, I tried to isolate each package (vite-vue-component, vite-auto-import..) but got no luck to find this error.


The error logs:

5:28:52 PM [vite] warning:
D:/Repos/test-regex-app/node_modules/.pnpm/local-pkg@0.4.1/node_modules/local-pkg/index.mjs
17 |
18 |  export function importModule(path) {
19 |    return import(path).then((i) => {
   |                  ^
20 |      if (i && i.default && i.default.__esModule)
21 |        return i.default
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: D:/Repos/test-regex-app/node_modules/.pnpm/local-pkg@0.4.1/node_modules/local-pkg/index.mjs?v=ee8d6c3e
5:28:52 PM [vite] new dependencies found: vitest, updating...
 > node_modules/.pnpm/local-pkg@0.4.1/node_modules/local-pkg/dist/shared.mjs:54:9: error: No matching export in "browser-external:fs" for import "existsSync"
    54 β”‚ import { existsSync, promises as fs3 } from "fs";
       β•΅          ~~~~~~~~~~

 > node_modules/.pnpm/local-pkg@0.4.1/node_modules/local-pkg/dist/shared.mjs:54:21: error: No matching export in "browser-external:fs" for import "promises"
    54 β”‚ import { existsSync, promises as fs3 } from "fs";
       β•΅                      ~~~~~~~~

 > node_modules/.pnpm/local-pkg@0.4.1/node_modules/local-pkg/dist/shared.mjs:62:13: error: No matching export in "browser-external:node:fs" for import "promises"
    62 β”‚ import fs, { promises as fsPromises } from "node:fs";
       β•΅              ~~~~~~~~

 > node_modules/.pnpm/local-pkg@0.4.1/node_modules/local-pkg/dist/shared.mjs:235:14: error: No matching export in "browser-external:node:fs" for import "promises"
    235 β”‚ import fs2, { promises as fsPromises2 } from "node:fs";
        β•΅               ~~~~~~~~

 > node_modules/.pnpm/local-pkg@0.4.1/node_modules/local-pkg/index.mjs:1:9: error: No matching export in "browser-external:path" for import "join"
    1 β”‚ import { join, dirname } from 'path'
      β•΅          ~~~~

 > node_modules/.pnpm/local-pkg@0.4.1/node_modules/local-pkg/index.mjs:1:15: error: No matching export in "browser-external:path" for import "dirname"
    1 β”‚ import { join, dirname } from 'path'
      β•΅                ~~~~~~~

 > node_modules/.pnpm/local-pkg@0.4.1/node_modules/local-pkg/index.mjs:2:9: error: No matching export in "browser-external:fs" for import "promises"
    2 β”‚ import { promises as fs, existsSync } from 'fs'
      β•΅          ~~~~~~~~

 > node_modules/.pnpm/local-pkg@0.4.1/node_modules/local-pkg/index.mjs:2:25: error: No matching export in "browser-external:fs" for import "existsSync"
    2 β”‚ import { promises as fs, existsSync } from 'fs'
      β•΅                          ~~~~~~~~~~

 > node_modules/.pnpm/local-pkg@0.4.1/node_modules/local-pkg/index.mjs:3:9: error: No matching export in "browser-external:module" for import "createRequire"
    3 β”‚ import { createRequire } from 'module'
      β•΅          ~~~~~~~~~~~~~

5:28:52 PM [vite] error while updating dependencies:
Error: Build failed with 9 errors:
node_modules/.pnpm/local-pkg@0.4.1/node_modules/local-pkg/dist/shared.mjs:54:9: error: No matching export in "browser-external:fs" for import "existsSync"
node_modules/.pnpm/local-pkg@0.4.1/node_modules/local-pkg/dist/shared.mjs:54:21: error: No matching export in "browser-external:fs" for import "promises"
node_modules/.pnpm/local-pkg@0.4.1/node_modules/local-pkg/dist/shared.mjs:62:13: error: No matching export in "browser-external:node:fs" for import "promises"
node_modules/.pnpm/local-pkg@0.4.1/node_modules/local-pkg/dist/shared.mjs:235:14: error: No matching export in "browser-external:node:fs" for import "promises"
node_modules/.pnpm/local-pkg@0.4.1/node_modules/local-pkg/index.mjs:1:9: error: No matching export in "browser-external:path" for import "join"
...
    at failureErrorWithLog (D:\Repos\test-regex-app\node_modules\.pnpm\esbuild@0.13.15\node_modules\esbuild\lib\main.js:1493:15)
    at D:\Repos\test-regex-app\node_modules\.pnpm\esbuild@0.13.15\node_modules\esbuild\lib\main.js:1151:28
    at runOnEndCallbacks (D:\Repos\test-regex-app\node_modules\.pnpm\esbuild@0.13.15\node_modules\esbuild\lib\main.js:941:63)
    at buildResponseToResult (D:\Repos\test-regex-app\node_modules\.pnpm\esbuild@0.13.15\node_modules\esbuild\lib\main.js:1149:7)
    at D:\Repos\test-regex-app\node_modules\.pnpm\esbuild@0.13.15\node_modules\esbuild\lib\main.js:1258:14
    at D:\Repos\test-regex-app\node_modules\.pnpm\esbuild@0.13.15\node_modules\esbuild\lib\main.js:629:9
    at handleIncomingPacket (D:\Repos\test-regex-app\node_modules\.pnpm\esbuild@0.13.15\node_modules\esbuild\lib\main.js:726:9)
    at Socket.readFromStdout (D:\Repos\test-regex-app\node_modules\.pnpm\esbuild@0.13.15\node_modules\esbuild\lib\main.js:596:7)
    at Socket.emit (node:events:390:28)
    at addChunk (node:internal/streams/readable:315:12)
5:28:53 PM [vite] warning:
D:/Repos/test-regex-app/node_modules/.pnpm/local-pkg@0.4.1/node_modules/local-pkg/index.mjs
17 |
18 |  export function importModule(path) {
19 |    return import(path).then((i) => {
   |                  ^
20 |      if (i && i.default && i.default.__esModule)
21 |        return i.default
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: D:/Repos/test-regex-app/node_modules/.pnpm/local-pkg@0.4.1/node_modules/local-pkg/index.mjs
hannoeru commented 2 years ago

In vite.config.ts add ignore: ['test'] to unplugin-auto-import's options. This is caused by auto import test from vitest.

You can debug this using vite-plugin-inspect.

γ‚Ήγ‚―γƒͺγƒΌγƒ³γ‚·γƒ§γƒƒγƒˆ 2022-01-11 1 16 34
antfu commented 2 years ago

Fixed in unplugin-auto-import@0.5.7