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

[WxtBuilder]: importEntrypoint is causing xxx not defined error. #1281

Open
5 tasks done
nishu-murmu opened this issue Dec 17, 2024 · 1 comment
Open
5 tasks done
Labels
bug Something isn't working

Comments

@nishu-murmu
Copy link
Contributor

Describe the bug

open-source-1
As entrypointLoader is going to be deparecated or has, by default vite-node to import entrypoints as of version 0.19.0

using await wxt.builder.importEntrypoint(entrypointPath) to import options is breaking.

Reproduction

add a file in modules sub-folder of the project
Add this below code

demo.ts

import { addEntrypoint, defineWxtModule } from 'wxt/modules';
import path, { resolve } from 'node:path';

export default defineWxtModule(async (wxt) => {
  const entrypointPath = resolve(
    path.join('src', 'entrypoints'),
    'unlisted.ts',
  );

  console.log({
    entrypointPath,
    dd: await wxt.builder.importEntrypoint(entrypointPath),
  });
  addEntrypoint(wxt, {
    type: 'unlisted-script',
    name: 'demo-module',
    inputPath: entrypointPath,
    outputDir: wxt.config.outDir,
    options: {},
  });
});

Add a unlisted.ts file inside entrypoints sub-folder of the project.

unlisted.ts

export default defineUnlistedScript(() => {
  console.log('injected');
});

Try running

pnpm build

Steps to reproduce

No response

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (8) x64 Intel(R) Core(TM) i3-10105 CPU @ 3.70GHz
    Memory: 827.90 MB / 7.84 GB
  Binaries:
    Node: 22.0.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.2.5 - C:\Program Files\nodejs\npm.CMD
    pnpm: 9.13.0 - C:\Program Files\nodejs\pnpm.CMD
  Browsers:
    Edge: Chromium (131.0.2903.86)
    Internet Explorer: 11.0.22621.3527

Used Package Manager

pnpm

Validations

@nishu-murmu nishu-murmu added the pending-triage Someone (usually a maintainer) needs to look into this to see if it's a bug label Dec 17, 2024
@aklinker1
Copy link
Collaborator

Ahh, yeah, that's a problem... importEntrypoint won't work when called inside the setup function directly... It needs to wait for the config:resolved hook to run before it actually works. It is just incompatible with addEntrypoint :/

Instead, I'd recommend implementing the function yourself and importing the entrypoint inside the hook:

https://github.com/wxt-dev/wxt/blob/main/packages%2Fwxt%2Fsrc%2Fmodules.ts#L56-L58

It's only 3 lines. We should probably deprecate that function for this reason :/ Or update it to automatically import the options if not provided.

@aklinker1 aklinker1 added bug Something isn't working and removed pending-triage Someone (usually a maintainer) needs to look into this to see if it's a bug labels Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants