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

import.meta.glob doesn't work #635

Closed
Tracked by #506
OrlS15 opened this issue Apr 28, 2024 · 2 comments
Closed
Tracked by #506

import.meta.glob doesn't work #635

OrlS15 opened this issue Apr 28, 2024 · 2 comments
Labels
duplicate This issue or pull request already exists

Comments

@OrlS15
Copy link

OrlS15 commented Apr 28, 2024

Describe the bug

// entrypoints/content.ts
const routes: Record<string, any> = import.meta.glob("../providers/*", {
  eager: true,
})
const matches = Object.keys(routes).flatMap((k) => routes[k].default.paths)

export default defineContentScript({
  matches,
  async main() {
    console.log("Hello content.")
  },
})

// providers/A.ts
export default {
  paths: ["*://*.example.com/*"],
}

OUTPUT:

ERROR  import_meta.glob is not a function                                                                                                             19:55:49  

 at C:/Users/Orlando/Desktop/test-wxt/entrypoints/content.ts:25:28
 at evalModule (node_modules\.pnpm\[email protected]\node_modules\jiti\dist\jiti.js:1:256443)
 at jiti (node_modules\.pnpm\[email protected]\node_modules\jiti\dist\jiti.js:1:254371)
 at importEntrypointFile (/C:/Users/Orlando/Desktop/test-wxt/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/wxt/dist/cli.js:2278:23)
 at async getContentScriptEntrypoint (/C:/Users/Orlando/Desktop/test-wxt/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/wxt/dist/cli.js:1528:35)
 at async /C:/Users/Orlando/Desktop/test-wxt/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/wxt/dist/cli.js:1308:18
 at async Promise.all (index 1)
 at async findEntrypoints (/C:/Users/Orlando/Desktop/test-wxt/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/wxt/dist/cli.js:1294:23)
 at async internalBuild (/C:/Users/Orlando/Desktop/test-wxt/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/wxt/dist/cli.js:3165:23)
 at async buildAndOpenBrowser (/C:/Users/Orlando/Desktop/test-wxt/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/wxt/dist/cli.js:3494:28)

✖ Command failed after 936 ms                                                                                                                         19:55:49

ERROR  Failed to load entrypoint: entrypoints\content.ts                                                                                              19:55:49  

 at importEntrypointFile (/C:/Users/Orlando/Desktop/test-wxt/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/wxt/dist/cli.js:2290:13)
 at async getContentScriptEntrypoint (/C:/Users/Orlando/Desktop/test-wxt/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/wxt/dist/cli.js:1528:35)
 at async /C:/Users/Orlando/Desktop/test-wxt/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/wxt/dist/cli.js:1308:18
 at async Promise.all (index 1)
 at async findEntrypoints (/C:/Users/Orlando/Desktop/test-wxt/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/wxt/dist/cli.js:1294:23)
 at async internalBuild (/C:/Users/Orlando/Desktop/test-wxt/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/wxt/dist/cli.js:3165:23)
 at async buildAndOpenBrowser (/C:/Users/Orlando/Desktop/test-wxt/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/wxt/dist/cli.js:3494:28)
 at async Object.start (/C:/Users/Orlando/Desktop/test-wxt/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/wxt/dist/cli.js:3459:9)  at async /C:/Users/Orlando/Desktop/test-wxt/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/wxt/dist/cli.js:3980:5
 at async CAC.<anonymous> (/C:/Users/Orlando/Desktop/test-wxt/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/wxt/dist/cli.js:3911:22)

To Reproduce

  1. Create a new project pnpm dlx wxt@latest init <project-name>
  2. Add the 2 files listed in Describe the bug section
  3. pnpm run dev

OR

test-wxt.zip
Steps to reproduce the bug using the reproduction:

  1. Install dependencies: pnpm i
  2. Start dev mode: pnpm dev

Expected behavior

no error

Environment

  System:
    OS: Windows 10 10.0.19045
    CPU: (12) x64 AMD Ryzen 5 5600X 6-Core Processor
    Memory: 7.18 GB / 15.92 GB
  Binaries:
    Node: 21.5.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.5.2 - C:\Program Files\nodejs\npm.CMD
    pnpm: 9.0.6 - ~\AppData\Roaming\npm\pnpm.CMD
  Browsers:
    Edge: Chromium (123.0.2420.97)
    Internet Explorer: 11.0.19041.3636
@OrlS15 OrlS15 added the triage Bug or problem that needs to be looked into label Apr 28, 2024
@aklinker1
Copy link
Collaborator

aklinker1 commented Apr 28, 2024

Duplicate/apart of #506, will be fixed after I get #585 finished.

Vite isn't used to load entrypoints during build when reading entrypoint options, like content script matches, so you can't use Vite APIs, like import.meta.glob, outside the main function.

@aklinker1 aklinker1 added duplicate This issue or pull request already exists and removed triage Bug or problem that needs to be looked into labels May 3, 2024
@aklinker1
Copy link
Collaborator

I'm gonna close this issue, it will be fixed in #506, follow that one for updates.

@aklinker1 aklinker1 closed this as not planned Won't fix, can't repro, duplicate, stale May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants