crxjs / chrome-extension-tools

Bundling Chrome Extensions can be pretty complex. It doesn't have to be.
https://crxjs.dev/vite-plugin
2.98k stars 192 forks source link

[crx:content-script-resources] Error: vite manifest is missing #846

Closed NicholasJupiter closed 10 months ago

NicholasJupiter commented 11 months ago

Build tool

Vite

Where do you see the problem?

Describe the bug

vite v5.0.4 building for production... ✓ 1426 modules transformed. [crx:content-script-resources] Error: vite manifest is missing at Object.renderCrxManifest (file:///Users/xiongyi/Desktop/wongta/extension-x-tower/node_modules/@crxjs/vite-plugin/dist/index.mjs:3240:21) at Object.generateBundle (file:///Users/xiongyi/Desktop/wongta/extension-x-tower/node_modules/@crxjs/vite-plugin/dist/index.mjs:2922:60) at async Bundle.generate (file:///Users/xiongyi/Desktop/wongta/extension-x-tower/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:16973:9) at async file:///Users/xiongyi/Desktop/wongta/extension-x-tower/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:19519:27 at async catchUnfinishedHookActions (file:///Users/xiongyi/Desktop/wongta/extension-x-tower/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:18950:16) at async build (file:///Users/xiongyi/Desktop/wongta/extension-x-tower/node_modules/vite/dist/node/chunks/dep-4RECYSE1.js:66261:22) at async CAC. (file:///Users/xiongyi/Desktop/wongta/extension-x-tower/node_modules/vite/dist/node/cli.js:845:9) [crx:manifest-post] Error in crx:content-script-resources.renderCrxManifest ✓ built in 3.63s error during build: Error: Error in crx:content-script-resources.renderCrxManifest at Object.generateBundle (file:///Users/xiongyi/Desktop/wongta/extension-x-tower/node_modules/@crxjs/vite-plugin/dist/index.mjs:2933:19) at async Bundle.generate (file:///Users/xiongyi/Desktop/wongta/extension-x-tower/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:16973:9) at async file:///Users/xiongyi/Desktop/wongta/extension-x-tower/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:19519:27 at async catchUnfinishedHookActions (file:///Users/xiongyi/Desktop/wongta/extension-x-tower/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:18950:16) at async build (file:///Users/xiongyi/Desktop/wongta/extension-x-tower/node_modules/vite/dist/node/chunks/dep-4RECYSE1.js:66261:22) at async CAC. (file:///Users/xiongyi/Desktop/wongta/extension-x-tower/node_modules/vite/dist/node/cli.js:845:9) error Command failed with exit code 1.

Reproduction

vite build

Logs

No response

System Info

"@crxjs/vite-plugin": "^1.0.14",
"vite": "^5.0.0"

Severity

annoyance

sqs commented 11 months ago

I am also seeing this on Vite 5. It is because Vite 5 renamed the manifest file to .vite/manifest.json, but @crxjs/vite-plugin tries to look for it at manifest.json.

Here is a workaround that appears to work (in your vite.config.ts):

const viteManifestHackIssue846: Plugin & { renderCrxManifest: (manifest: any, bundle: any) => void } = {
    // Workaround from https://github.com/crxjs/chrome-extension-tools/issues/846#issuecomment-1861880919.
    name: 'manifestHackIssue846',
    renderCrxManifest(_manifest, bundle) {
        bundle['manifest.json'] = bundle['.vite/manifest.json']
        bundle['manifest.json'].fileName = 'manifest.json'
        delete bundle['.vite/manifest.json']
    },
}

export default defineConfig({
    plugins: [/* ... */, viteManifestHackIssue846, crx(/* ... */)],
    // ....
})
kaminskypavel commented 10 months ago

This was actually addressed in this PR there's no need to hack vite anymore

hyusetiawan commented 8 months ago

I am not sure why this is marked as completed, I updated to the latest and it's still giving me the same manifest missing issue, the workaround posted by @sqs still works.

dffxd-suntra commented 8 months ago

I am not sure why this is marked as completed, I updated to the latest and it's still giving me the same manifest missing issue, the workaround posted by @sqs still works.

yes,I agree with you. But this patch will cause new problems: old files will not be cleaned automatically, I don't know if it is my problem

Crocsx commented 7 months ago

this is still the case I believe today

HawtinZeng commented 4 months ago

A workaround for temperory: image

Kinzi commented 4 months ago

@HawtinZeng this worked for me.....

LukasDzenk commented 3 months ago

@HawtinZeng Worked like a charm. Much appreciated.

HawtinZeng commented 3 months ago

Maybe we need to endure this bug until Vite api get stable for a while.

bitdom8 commented 3 months ago

Revise the dist again would be painful each time, please resolve this

ChristopherBull commented 3 months ago

The workaround given above works for v1.x.x of this project if you also install newer versions of Vite v4+.

If like me you have Vite v5 (due to other plugin peer dependencies) and the latest stable version of this project still gives an error, you can install v2-beta of this project. This is the release that fixes this issue (but install a newer version ofc): https://github.com/crxjs/chrome-extension-tools/releases/tag/%40crxjs%2Fvite-plugin%402.0.0-beta.22