unplugin-vue2-script-setup icon indicating copy to clipboard operation
unplugin-vue2-script-setup copied to clipboard

defineProps is not defined with ESbuild

Open KevinBerthier opened this issue 2 years ago • 10 comments

I moved from webpack to ESbuild but I get ReferenceError: defineProps is not defined

My config is a bit different from the doc : plugins: [rails(), vuePlugin(), require('unplugin-vue2-script-setup/esbuild').default()], instead of plugins: [rails(), vuePlugin(), require('unplugin-vue2-script-setup/esbuild')()],

KevinBerthier avatar Apr 26 '22 08:04 KevinBerthier

try plugins: [rails(), require('unplugin-vue2-script-setup/esbuild').default(), vuePlugin(), ],

xiaoxiangmoe avatar Apr 26 '22 08:04 xiaoxiangmoe

@xiaoxiangmoe I get :

✘ [ERROR] The JSX syntax extension is not currently enabled

    apps/notification-center/NotificationCenter.vue:1:0:
      1 │ <template>
        ╵ ^

  The esbuild loader for this file is currently set to "js" but it must be set to "jsx" to be able
  to parse JSX syntax. You can use "loader: { '.js': 'jsx' }" to do that.

Here is my config :

const config = {
  absWorkingDir: path.join(process.cwd(), 'app/javascript'),
  bundle: true,
  chunkNames: 'chunks/[name]-[hash]',
  entryPoints,
  format: 'esm',
  minify: process.env.RAILS_ENV == 'production',
  metafile: true,
  outdir: path.join(process.cwd(), 'app/assets/builds'),
  platform: 'browser',
  plugins: [rails(), require('unplugin-vue2-script-setup/esbuild').default(), vuePlugin()],
  sourcemap: process.env.RAILS_ENV != 'production',
  splitting: true,
  treeShaking: true,
  loader: {
    '.svg': 'dataurl'
  }
}

KevinBerthier avatar Apr 26 '22 08:04 KevinBerthier

Can you provide a minimal reproducible repo

xiaoxiangmoe avatar Apr 28 '22 05:04 xiaoxiangmoe

@xiaoxiangmoe here it is https://github.com/KevinBerthier/unplugin-vue2-script-setup-esbuild-bug

KevinBerthier avatar Apr 28 '22 08:04 KevinBerthier

@sxzz Can you help to fix this?

xiaoxiangmoe avatar Apr 28 '22 08:04 xiaoxiangmoe

@sxzz Can you help to fix this?

OK, I'll check it later.

sxzz avatar Apr 28 '22 08:04 sxzz

It seems to be a problem with unplugin or esbuild-vue, I'll try to fix it later.

sxzz avatar Apr 28 '22 12:04 sxzz

We need to wait for esbuild to resolve this issue https://github.com/evanw/esbuild/issues/1902

sxzz avatar Apr 28 '22 13:04 sxzz

Maybe you can use this plugin https://github.com/nativew/esbuild-plugin-pipe

sxzz avatar Jun 23 '22 16:06 sxzz

I wrote a plugin esbuild-plugin-transform. You can try this.

sxzz avatar Jul 01 '22 14:07 sxzz