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
some problems about branch:refactor/mv3 until 2022/11/22 #104
Comments
Problem1. remove Problem2. can be solved Problem3. HMR is unstable in MV3 as expected because the implementation is a little tricky, and that's why it's still not merged into main branch. needs more investigation. |
Problem 4
|
@tmkx I followed your instruction of adding noExternal: ['axios'] in tsup.config.ts, but the error besides, so it means that |
Problem5background script is not bundled by Vite, there is no |
It seems that |
so how to use a background script to always inject the latest version of content-scripts in MV3, as as browsers would cache them for each reload |
Maybe you can create a WebSocket connection to Vite server, cleanup & remount content-scripts to the page when receiving updates? It's not implemented yet. |
@tmkx, for problem 4, I have searched a similar issue which also got errors when bundling axios with tsup. axios/axios#4842. It explains it maybe caused by nodejs builtin modules when using for the browser. so I followed his instruction, firstly, add yarn add esbuild-plugins-node-modules-polyfill --dev then , modify tsup.config.ts by adding: import { nodeModulesPolyfillPlugin } from 'esbuild-plugins-node-modules-polyfill'
export default defineConfig(() => ({
...
esbuildPlugins: [nodeModulesPolyfillPlugin()],
...
})) this time, then, I tried to use axios to request something. Indeedly, the error {
"message": "Adapter http is not supported by the environment",
"name": "AxiosError",
"stack": "AxiosError: Adapter http is not supported by the environment\n at Object.getAdapter (chrome-extension://hbidegeigejmmpppbdmbbmobgcingopm/dist/background/index.mjs:69518:15)\n at Axios.dispatchRequest (chrome-extension://hbidegeigejmmpppbdmbbmobgcingopm/dist/background/index.mjs:69554:36)\n at Axios.request (chrome-extension://hbidegeigejmmpppbdmbbmobgcingopm/dist/background/index.mjs:69803:33)\n at Axios.get (chrome-extension://hbidegeigejmmpppbdmbbmobgcingopm/dist/background/index.mjs:69822:17)\n at Function.wrap [as get] (chrome-extension://hbidegeigejmmpppbdmbbmobgcingopm/dist/background/index.mjs:54941:15)\n at chrome-extension://hbidegeigejmmpppbdmbbmobgcingopm/dist/background/index.mjs:70515:15",
"code": "ERR_NOT_SUPPORT",
"status": null
} so I found an fetch adapter for axios to install: yarn add @vespaiach/axios-fetch-adapter --dev and use it in background.ts import axios from 'axios'
import fetchAdapter from '@vespaiach/axios-fetch-adapter'
const axiosTest = () => {
const axiosInstance = axios.create({ adapter: fetchAdapter })
return axiosInstance
}
console.log(axiosTest) but this time, new errors occured when bundling: ✘ [ERROR] Could not resolve "axios/lib/core/settle"
node_modules/@vespaiach/axios-fetch-adapter/index.js:2:19:
2 │ import settle from 'axios/lib/core/settle';
╵ ~~~~~~~~~~~~~~~~~~~~~~~
The path "./lib/core/settle" is not exported by package "axios":
node_modules/axios/package.json:6:13:
6 │ "exports": {
╵ ^
You can mark the path "axios/lib/core/settle" as external to exclude it from the bundle, which
will remove this error.
✘ [ERROR] Could not resolve "axios/lib/helpers/buildURL"
node_modules/@vespaiach/axios-fetch-adapter/index.js:3:21:
3 │ import buildURL from 'axios/lib/helpers/buildURL';
╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The path "./lib/helpers/buildURL" is not exported by package "axios":
node_modules/axios/package.json:6:13:
6 │ "exports": {
╵ ^
You can mark the path "axios/lib/helpers/buildURL" as external to exclude it from the bundle,
which will remove this error.
✘ [ERROR] Could not resolve "axios/lib/core/buildFullPath"
node_modules/@vespaiach/axios-fetch-adapter/index.js:4:26:
4 │ import buildFullPath from 'axios/lib/core/buildFullPath';
╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The path "./lib/core/buildFullPath" is not exported by package "axios":
node_modules/axios/package.json:6:13:
6 │ "exports": {
╵ ^
You can mark the path "axios/lib/core/buildFullPath" as external to exclude it from the bundle,
which will remove this error.
✘ [ERROR] Could not resolve "axios/lib/utils"
node_modules/@vespaiach/axios-fetch-adapter/index.js:5:62:
5 │ import { isUndefined, isStandardBrowserEnv, isFormData } from 'axios/lib/utils';
╵ ~~~~~~~~~~~~~~~~~
The path "./lib/utils" is not exported by package "axios":
node_modules/axios/package.json:6:13:
6 │ "exports": {
╵ ^
You can mark the path "axios/lib/utils" as external to exclude it from the bundle, which will
remove this error. Oh,my god! Why can't tsup handle so common packages? It seems tsup can't resolve the path |
There is a solution:
// tsup.config.ts
export default defineConfig(() => ({
+ platform: 'browser',
})) import axios from 'axios'
import fetchAdapter from '@vespaiach/axios-fetch-adapter'
const instance = axios.create({ adapter: fetchAdapter })
instance.get('https://httpbin.org/get').then(res => console.log(res.data)) |
@tmkx thanks for your suggestion, it's fixed. It's hardly to relate to the compatible problem by the poor prompt! But it's tedious and labourious to be bundled by vite and tsup separately, as some scripts can't be reused for them together (such as |
background can run as HTML script in MV2, but it should be a service worker in MV3, it's different. take a look at the first refactor commit |
@tmkx Problem 6 add in import 'quasar/src/css/index.sass' errors when bundle: /home/john/project/testscratch/typescript-demos/bex-demo-mv3/node_modules/.pnpm/sass@1.32.12/node_modules/sass/sass.dart.js:13172
var error = new self.Error(message);
^
Error: [sass] This file is already being loaded.
╷
1 │ @import '/home/john/project/testscratch/typescript-demos/bex-demo-mv3/src/quasar-variables.sass'
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
╵
src/quasar-variables.sass 1:9 root stylesheet
at Object._newRenderError (/home/john/project/testscratch/typescript-demos/bex-demo-mv3/node_modules/.pnpm/sass@1.32.12/node_modules/sass/sass.dart.js:13172:19)
at Object._wrapException (/home/john/project/testscratch/typescript-demos/bex-demo-mv3/node_modules/.pnpm/sass@1.32.12/node_modules/sass/sass.dart.js:12998:16)
...
at Object._rootRunBinary (/home/john/project/testscratch/typescript-demos/bex-demo-mv3/node_modules/.pnpm/sass@1.32.12/node_modules/sass/sass.dart.js:4749:18) {
formatted: 'Error: This file is already being loaded.\n' +
' ╷\n' +
"1 │ @import '/home/john/project/testscratch/typescript-demos/bex-demo-mv3/src/quasar-variables.sass'\n" +
' │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n' +
' ╵\n' +
' src/quasar-variables.sass 1:9 root stylesheet',
line: 1,
column: 9,
file: '/home/john/project/testscratch/typescript-demos/bex-demo-mv3/src/quasar-variables.sass',
status: 1,
id: '/home/john/project/testscratch/typescript-demos/bex-demo-mv3/src/quasar-variables.sass',
frame: 'Error: This file is already being loaded.\n' +
' ╷\n' +
"1 │ @import '/home/john/project/testscratch/typescript-demos/bex-demo-mv3/src/quasar-variables.sass'\n" +
' │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n' +
' ╵\n' +
' src/quasar-variables.sass 1:9 root stylesheet',
plugin: 'vite:css',
pluginCode: "@import '/home/john/project/testscratch/typescript-demos/bex-demo-mv3/src/quasar-variables.sass'\n" +
"@import 'quasar/src/css/variables.sass'\n" +
'\n' +
'\n' +
'$primary : #1976D2\n' +
'$secondary : #26A69C\n' +
'$accent : #9C27B0\n' +
'\n' +
'$dark : #1D1D1D\n' +
'\n' +
'$positive : #21BA45\n' +
'$negative : #C10015\n' +
'$info : #31CCEC\n' +
'$warning : #F2C037',
loc: {
file: '/home/john/project/testscratch/typescript-demos/bex-demo-mv3/src/quasar-variables.sass',
line: 1,
column: 9
}
}
Node.js v18.12.0
ELIFECYCLE Command failed with exit code 1.
ERROR: "dev:web" exited with 1.
ELIFECYCLE Command failed with exit code 1. what's wrong with it? |
Have you tried this https://quasar.dev/start/vite-plugin? |
@tmkx yes, I followed their instructions and modified following files. pnpm add quasar @quasar/extras @quasar/vite-plugin sass@1.32.12 -D vite.config.ts import { quasar, transformAssetUrls } from '@quasar/vite-plugin'
...
export const sharedConfig: UserConfig = {
root: r('src'),
resolve: {
alias: {
'~/': `${r('src')}/`,
},
},
plugins: [
Vue({
template: { transformAssetUrls },
}),
quasar({
sassVariables: r('src/quasar-variables.sass'),
}),]
...
}
...
src/popup/main.ts
```ts
import { createApp } from 'vue'
// quasar
import { Quasar } from 'quasar'
import iconSet from 'quasar/icon-set/svg-material-icons'
// Import icon libraries
import '@quasar/extras/material-icons/material-icons.css'
import 'quasar/src/css/index.sass'
import App from './Popup.vue'
import '../styles'
const app = createApp(App)
app.use(Quasar, {
iconSet,
}).mount('#app') src/quasar-vaiables.sass $primary : #1976D2
$secondary : #26A69C
$accent : #9C27B0
$dark : #1D1D1D
$positive : #21BA45
$negative : #C10015
$info : #31CCEC
$warning : #F2C037 then I'm confused that for the same codes, why mv2 boilerplate is ok, but mv3 not to bundle sass? |
it seems that HMR does not work with quasar sass variables. I'm not familiar with quasar, you can use |
It's a good provisional way to resolve this problem ! Thanks,now I can go along it again! Until now, it's a nearly perfect boilerplate for mv3 supporting HMR |
@tmkx Problem 7 |
you can declare missing definitions like this: // shim.d.ts
declare module 'webextension-polyfill' {
declare namespace Browser {
const mv3: {
hello: () => void;
};
}
export = Browser;
} |
That should be the last choice because I have to manually written all new-added mv3 type definitions one by one. It's very tedious. Since mv3 has been published from 2020, it's weird that there hasn't yet been an public mv3 types package in community for the past two years. |
There is an official type definitions package, but it's for Chrome only, have a try!
// tsconfig.json
"types": [
"vite/client",
+ "chrome"
], chrome.tabGroups.get() |
Hi @tmkx, any advance on Prob. 3? I recently update my project to the mv3 template, most functions works fine for me, but the dev model for vite. It won't hot reload modification of .ts file, like the vuex storage index.ts I used in my project. 9:38:47 AM [vite] page reload store/index.ts
ESM Build start
ESM extension/dist/mv3client.mjs 38.74 KB
ESM extension/dist/background/index.mjs 100.08 KB
ESM ⚡️ Build success in 12ms However, the file in the extention dir I investigate the MV3Hmr vite plugin, but I don't understand how it works. |
HMR is supported in the if there still have any problems, please reopen it :) |
Describe the bug
some problems about branch:refactor/mv3 until 2022/11/22
I downloaded the latest source code:
problem 1
there is a
ERR_PNPM_FETCH_404
error when using pnpm to install.but it's normal if turn to yarn.
problem 2
scripts/client.ts
line:12the socket port is hardcoded, so If the port is set by env variables, the follwoing error would occur:
problem3
HMR is not stable, sometimes the changed reflected immediately, but sometimes, the changes can't be rendered in time. especially when continuously change the code. I haven't found what's the problem is. @tmkx
Reproduction
reproduction
System Info
Used Package Manager
yarn
Validations
The text was updated successfully, but these errors were encountered: