crxjs / chrome-extension-tools

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

TypeError [ERR_IMPORT_ASSERTION_TYPE_MISSING]: #450

Closed altryne closed 2 years ago

altryne commented 2 years ago

Build tool

Vite

Where do you see the problem?

Describe the bug

Following the basic instructions shows an error on importing json. TypeError [ERR_IMPORT_ASSERTION_TYPE_MISSING]:... needs an import assertion of type "json"

Reproduction

Follow the CRXJS basic steps with node v18.6.0

Logs

[ERR_IMPORT_ASSERTION_TYPE_MISSING]: Module "file:///Users/USERNAME/projects/vite-project/manifest.json" needs an import assertion of type "json"
    at new NodeError (node:internal/errors:387:5)
    at validateAssertions (node:internal/modules/esm/assert:82:15)
    at defaultLoad (node:internal/modules/esm/load:84:3)
    at nextLoad (node:internal/modules/esm/loader:173:28)
    at ESMLoader.load (node:internal/modules/esm/loader:616:26)
    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:472:22)
    at new ModuleJob (node:internal/modules/esm/module_job:63:26)
    at #createModuleJob (node:internal/modules/esm/loader:491:17)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:449:34)
    at async ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:78:21)

System Info

System:
    OS: macOS 12.3.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 107.47 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 18.6.0 - /usr/local/bin/node
    npm: 8.13.2 - /usr/local/bin/npm
    Watchman: 2022.03.21.00 - /opt/homebrew/bin/watchman
  Browsers:
    Brave Browser: 103.1.40.113
    Chrome: 103.0.5060.114
    Safari: 15.4
  npmPackages:
    @crxjs/vite-plugin: ^1.0.12 => 1.0.12 
    vite: ^3.0.0 => 3.0.0 


### Severity

blocking all usage of RPCE
chasebank commented 2 years ago

Looks like including the type assertion in the Vite config fixes this.

import { defineConfig } from 'vite'
import { crx } from '@crxjs/vite-plugin'
-import manifest from './manifest.json'
+import manifest from './manifest.json' assert {type: 'json'}

export default defineConfig({
  plugins: [crx({ manifest })],
})
altryne commented 2 years ago

It does indeed, that's how I've been working so far, just wanted to highlight as documentation has no record of assertion types

jacksteamdev commented 2 years ago

PRs are welcome! Docs are in packages/vite-plugin-docs and use Docusaurus.

Notes

Looks like this was introduced in Node 17, so docs will need to support both since we support Node >=14.

PMNagarro commented 5 months ago

I am facing same issue when updated the playwright version to 1.45. Using the session cookies to get store in state file and then issue is happening for that json file. Does it has anything to do with node.js and Playwright versions compatibility ?

TypeError [ERR_IMPORT_ATTRIBUTE_MISSING]: Module "file:///C:/e2e/helpers/state/user-gda-P1.1720012578177.json" needs an import attribute of "type: json" at validateAttributes (node:internal/modules/esm/assert:88:15) at defaultLoad (node:internal/modules/esm/load:143:3) at async nextLoad (node:internal/modules/esm/hooks:791:22) at async nextLoad (node:internal/modules/esm/hooks:791:22) at async Hooks.load (node:internal/modules/esm/hooks:383:20) at async MessagePort.handleMessage (node:internal/modules/esm/worker:255:18) { code: 'ERR_IMPORT_ATTRIBUTE_MISSING'