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

production build fails with @crxjs/vite-plugin #11

Open
xko opened this issue May 31, 2023 · 3 comments
Open

production build fails with @crxjs/vite-plugin #11

xko opened this issue May 31, 2023 · 3 comments

Comments

@xko
Copy link

xko commented May 31, 2023

I was trying to make a POC chrome extension using @crxjs/vite-plugin. npm run dev worked great (live-reloaded, catched changes in scala code etc.) , but npm run build failed:

[commonjs--resolver] buildStart must be called before resolveId
error during build:
Error: buildStart must be called before resolveId
    at Object.resolveId (file:///home/xko/dev/schrome/node_modules/@scala-js/vite-plugin-scalajs/dist/index.js:52:23)
    at file:///home/xko/dev/schrome/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:24656:40
    at async PluginDriver.hookFirstAndGetPlugin (file:///home/xko/dev/schrome/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:24556:28)
    at async resolveId (file:///home/xko/dev/schrome/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:23400:26)
    at async ModuleLoader.resolveId (file:///home/xko/dev/schrome/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:23664:15)
    at async Object.resolveId (file:///home/xko/dev/schrome/node_modules/vite/dist/node/chunks/dep-4d3eff22.js:7990:10)
    at async PluginDriver.hookFirstAndGetPlugin (file:///home/xko/dev/schrome/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:24556:28)
    at async resolveId (file:///home/xko/dev/schrome/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:23400:26)
    at async ModuleLoader.resolveId (file:///home/xko/dev/schrome/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:23664:15)
    at async file:///home/xko/dev/schrome/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:23952:50

To reproduce:

  • clone the repo
  • npm i*
  • npm run build
@sjrd
Copy link
Member

sjrd commented May 31, 2023

Maybe crxjs/vite-plugin does not respect the Vite specification? The Vite documentation clearly says that buildStart will be called once when the build starts. vite-plugin-scalajs needs this method to be called to read options and resolve sbt projects. It cannot process resolveId before that has been done.

@xko
Copy link
Author

xko commented May 31, 2023

before I go there to create an issue, I'd like to clarify couple of things (sorry if I'd sound stupid, I'm a backend developer and this is my 1st journey JS and frontend world :)):

  • can crxjs/vite-plugin actually violate this spec? from what I read in vite and rollup docs, vite is fully responsible for ensuring hooks call order, plugins have no contol here. maybe the issue should go to vite instead?
  • can this have anything to do with buildStart hook, being parallel? maybe there's some sort of race condition between 2 plugins?

@xko
Copy link
Author

xko commented May 31, 2023

@sjrd , after some random attempts, I was able to make it work by doing this in scala-js plugin:

        buildStart :{
            sequential: true,
            order: 'pre',
            async handler(options) {
                if (isDev === undefined)
                    throw new Error("configResolved must be called before buildStart");
                const task = isDev ? "fastLinkJSOutput" : "fullLinkJSOutput";
                const projectTask = projectID ? `${projectID}/${task}` : task;
                scalaJSOutputDir = await printSbtTask(projectTask, cwd);
            }
        },

I don't fully understand what I have changed, but if it makes sense to you, I'll create a PR

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