vite-plugin-mpa icon indicating copy to clipboard operation
vite-plugin-mpa copied to clipboard

TypeError: mpa is not a function

Open hikariyo opened this issue 3 years ago • 11 comments

I have no idea why mpa is an object containing default function rather than the function itself.

image

Obviously, using mpa.default() can apply the correct function, but it's definitely not what we want.

hikariyo avatar Oct 02 '22 09:10 hikariyo

Here is my tsconfig.json

{
  "compilerOptions": {
    "target": "ESNext",
    "useDefineForClassFields": true,
    "module": "ESNext",
    "moduleResolution": "Node",
    "strict": true,
    "jsx": "preserve",
    "sourceMap": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "esModuleInterop": true,
    "lib": ["ESNext", "DOM"],
    "skipLibCheck": true
  },
  "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
  "references": [{ "path": "./tsconfig.node.json" }]
}

hikariyo avatar Oct 02 '22 10:10 hikariyo

This error happens for me too.

svicalifornia avatar Nov 01 '22 09:11 svicalifornia

Same here

brunocapdevila avatar Dec 02 '22 19:12 brunocapdevila

I fix this with mpa.default(), not mpa()

  plugins: [
    vue(),
    mpa.default(),
  ],

terwer avatar Dec 02 '22 19:12 terwer

mpa.default() 这样子确实可以跑通,但会报 TS 类型错误,如下图, image

其实,只需要修改 /node_modules/vite-plugin-mpa/dist/index.js 源码导出模块的方式,不仅 TS 类型错误可以被解决,也可以正常以 mpa() 的形式使用

-exports.default = mpa;
+module.exports = mpa;

修改完源码后,用 patch-package 打个补丁后,在 vite-plugin-mpa 修复前都不会有啥后顾之忧了。

iTonyYo avatar Dec 08 '22 07:12 iTonyYo

@kifuan 是不是在package.json中使用了type: 'module'

CatLeeran avatar Apr 20 '23 08:04 CatLeeran

@kifuan Did you use type: 'module' in package.json

Yes, I use.

But when I try to use path module in vite.config.ts, I've got an error, I can't use __dirname, and mpa()

chuikoffru avatar Jun 02 '23 04:06 chuikoffru

I removed type: "module" from package.json, and fixed the error. Now I can use __dirname, path, and mpa()

chuikoffru avatar Jun 02 '23 04:06 chuikoffru

But, I should fixed tsconfig

"moduleResolution": "bundler",

And install @types/node

chuikoffru avatar Jun 02 '23 04:06 chuikoffru

Getting this error after updating to Vite 5 and after adding type=""module" in package.json as required in Vite 5 . Is there workaround this ?

RaminderRandhawa91 avatar Jan 22 '24 18:01 RaminderRandhawa91

mpa.default() 这样子确实可以跑通,但会报 TS 类型错误,如下图, image

其实,只需要修改 /node_modules/vite-plugin-mpa/dist/index.js 源码导出模块的方式,不仅 TS 类型错误可以被解决,也可以正常以 mpa() 的形式使用

-exports.default = mpa;
+module.exports = mpa;

修改完源码后,用 patch-package 打个补丁后,在 vite-plugin-mpa 修复前都不会有啥后顾之忧了。

令人遗憾,一年多了这个问题还没有被修复 😪

Jasonzyt avatar Apr 27 '24 09:04 Jasonzyt