Skip to content

import.meta.glob doesn't work #635

Closed as not planned
Closed as not planned

Description

@orls0xF

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

Activity

  1. added
    pending-triage
    on Apr 28, 2024
  2. aklinker1 commented on Apr 28, 2024

    @aklinker1
    Member

    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.

  3. added and removed
    pending-triage
    on May 3, 2024
  4. aklinker1 commented on May 3, 2024

    @aklinker1
    Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions