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

when using a nested dir and a nested vite.config.ts, crx doesn't respect the root when looking for entry points #917

Open
1 of 2 tasks
z-br opened this issue Sep 13, 2024 · 2 comments

Comments

@z-br
Copy link

z-br commented Sep 13, 2024

Build tool

Vite

Where do you see the problem?

  • In the browser
  • In the terminal

Describe the bug

I get the error RollupError: Could not resolve entry module "Popup.html". when building a nested project from a root package.json

If I change manifest to (erroneously) include the nested dir name , e.g.

{
  "manifest_version": 3,
  "name": "My React Chrome Extension",
  "version": "1.0.0",
  "description": "A Chrome extension built with React and TypeScript.",
  "permissions": ["storage", "tabs"],
  "action": {
    "default_popup": "extension/Popup.html"
  }
}

I can get the build to work, but then the extension doesn't work in chrome (unsuprising, it shouldnt have the dir name in there) .
image

I shouldn't need the nested dir name there because that dir is the root of the vite.config.js via root: __dirname configuration, which works for everything else. It just doesn't seem to work for crx. I tried to find a parameter to tell crx to use that as the root explicity but I can't find one. Is there a simple configuration parameter I am missing?

Reproduction

create a directory nested inside of an existing web probject, e.g. {project_root}/extension with extension/vite.config.ts as such:

import { resolve } from 'path';

import { crx } from '@crxjs/vite-plugin';
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';

import manifest from './public/manifest.json';

export default defineConfig({
  plugins: [react(), crx({ manifest })],
  root: __dirname, // Use the extension directory as root
  build: {
    outDir: '../dist-extension', // Output directory for the extension
    sourcemap: true,
    emptyOutDir: true,
  },
});

in root package.json, add script:

"build:extension": "vite build --config extension/vite.config.ts"

run pnpm run build:extension

Error:

RollupError: Could not resolve entry module "Popup.html".

Logs

No response

System Info

System:
    OS: macOS 14.1.1
    CPU: (16) arm64 Apple M3 Max
    Memory: 109.94 MB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.0 - ~/.nvm/versions/node/v20.11.0/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 10.2.4 - ~/.nvm/versions/node/v20.11.0/bin/npm
    pnpm: 9.0.0-alpha.1 - ~/.nvm/versions/node/v20.11.0/bin/pnpm
    bun: 1.0.20 - ~/.bun/bin/bun
  Browsers:
    Chrome: 128.0.6613.138
    Safari: 17.1
  npmPackages:
    @crxjs/vite-plugin: ^1.0.14 => 1.0.14
    vite: ^5.2.8 => 5.2.8

Severity

blocking all usage of RPCE

@Toumash
Copy link

Toumash commented Sep 14, 2024

Out of curiosity what setup is this lerna or something with extension as one of the packages?

@z-br
Copy link
Author

z-br commented Sep 14, 2024

Out of curiosity what setup is this lerna or something with extension as one of the packages?

Its just a normal (complicated) react app originally created from CRA and ported to vite. extension is just the subdirectory I put the chrome extension code/subproject in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants