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

Error in using uploadImages #279

Closed
Wesley1993 opened this issue Mar 3, 2023 · 7 comments
Closed

Error in using uploadImages #279

Wesley1993 opened this issue Mar 3, 2023 · 7 comments
Labels
question Further information is requested stale

Comments

@Wesley1993
Copy link

Wesley1993 commented Mar 3, 2023

version: 1.20.2
env: Vue2

image

@CPunisher
Copy link
Contributor

In bytemd, selectFiles is a function imported from select-files packages.
I tried uploadImages in official vue2 example, but I can't reproduce your error.
Can you provide a reproduction ?

@hhuangxm
Copy link

i had the same bug

vue version 2.6.11

@sevilen
Copy link

sevilen commented Apr 7, 2023

In bytemd, selectFiles is a function imported from select-files packages. I tried uploadImages in official vue2 example, but I can't reproduce your error. Can you provide a reproduction ?

official vue2 example works, the vue-nuxtjs example can reproduce.

@15079698746
Copy link

使用vue2 需将 @bytemd/vue 降低到1.17.1 版本,点击上传图片可正常使用

@CPunisher
Copy link
Contributor

It seems that there is something wrong with Webpack 4 when the code mixes commonjs and esm, i.e., webpack 4 transpile select-files to Module { default: function } instead of function, which causes this error.
image

Some issues related to webpack v4:
vuejs/pinia#675
webpack/webpack#6459
webpack/webpack#9509

I have come up with 3 solutions just for reference.

  1. Upgrade your webpack to v5
  2. Manually resolve all packages resolved as commonjs to corresponding esm file using aliases.
resolve: {
  alias: {
    bytemd$: path.resolve(__dirname, 'node_modules/bytemd/dist/index.mjs'),
    'tippy.js$': path.resolve(__dirname, 'node_modules/tippy.js/dist/tippy.esm'),
  }
}
  1. Force the use of commonjs by adding the following webpack configuration. Webpack v4 prefer to use module field(which points to esm file) in package.json(which points to cjs file) to the main field, thus exchanging their order can give priority to parsing their cjs files.
resolve: {
  mainFields: ['main', 'module']
}

I'm not sure the above solutions work, and welcome better solutions or in-depth discussions.

@github-actions
Copy link
Contributor

This issue is stale because it has been open for 60 days with no activity.

@github-actions github-actions bot added the stale label Jun 29, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jul 6, 2023

This issue was closed because it has been inactive for 7 days since being marked as stale.

@github-actions github-actions bot closed this as completed Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested stale
Projects
None yet
Development

No branches or pull requests

6 participants