Skip to content

Improved error message when entrypoint loading fails #1056

Description

@aklinker1

Describe the bug

const EXAMPLE = new MutationObserver();

export default defineContentScript({ ... });

I believe this is the most common question I get asked. Just need a better error message when the error include "Xyz is not defined", and point to this URL: https://wxt.dev/guide/go-further/entrypoint-loaders.html

Reproduction

const EXAMPLE = new MutationObserver();

export default defineContentScript({ ... });

Steps to reproduce

wxt prepare

System Info

System:
    OS: macOS 14.2.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 1.86 GB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.20.3 - ~/.asdf/installs/nodejs/18.20.3/bin/node
    Yarn: 1.22.22 - ~/.asdf/installs/nodejs/18.20.3/bin/yarn
    npm: 10.7.0 - ~/.asdf/plugins/nodejs/shims/npm
    pnpm: 9.12.0 - ~/.asdf/installs/nodejs/18.20.3/bin/pnpm
    bun: 1.1.27 - ~/.bunv/bin/bun
  Browsers:
    Chrome: 129.0.6668.90
    Safari: 17.2.1

Used Package Manager

pnpm

Validations

Activity

  1. added
    pending-triage
    and removed
    pending-triage
    on Oct 7, 2024
  2. aklinker1 commented on Oct 7, 2024

    @aklinker1
    MemberAuthor

    I thought I remembered already doing this... And I have:

    throw Error(
    `${filePath}: Cannot use imported variable "${variableName}" outside the main function. See https://wxt.dev/guide/go-further/entrypoint-side-effects.html`,
    { cause: err },
    );

    It's just in the wrong place, and isn't used with the vite-node entrypoint loader. So we just need to extract that try/catch further up the call tree.

  3. avi12 commented on Oct 17, 2024

    @avi12
    Contributor

    Another one that occurs as a result of wxt dev:
    image

  4. aklinker1 commented on Oct 18, 2024

    @aklinker1
    MemberAuthor

    Huh, that one is already customized, not sure why you're getting an empty string though :/

  5. avi12 commented on Oct 18, 2024

    @avi12
    Contributor

    I also noticed that whenever I update something and then the dev server reloads the extension, if I reload the web page, the content script won't run for some reason
    I have to reload the dev server every time I make a change and then reload the extension, which will trigger a reload of the web page

  6. aklinker1 commented on Oct 18, 2024

    @aklinker1
    MemberAuthor

    Seems related to #1074 (comment). Are you using a persistent profile?

  7. avi12 commented on Oct 18, 2024

    @avi12
    Contributor

    Yes
    In my YTTM project I'm only testing in a persistent profile, not temporarily loading Chrome instances

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions