vitejs / vite

Next generation frontend tooling. It's fast!
http://vite.dev
MIT License
68.44k stars 6.17k forks source link

Unexpected token export when consuming in Vue CLI app #3342

Closed adi518 closed 3 years ago

adi518 commented 3 years ago

Describe the bug

I have a single component library that I build with Vite and when trying to consume it in a Vue CLI based app, it fails with Unexpected token 'export'. It appears to be something with the ESM build output by Vite. Webpack can read ESM, so I'm not sure why it doesn't work out of the box.

Reproduction

  1. Clone and Install: https://github.com/adi518/vue-facebook-login/tree/next
  2. Build vue-facebook-login-component-next.
  3. Start the app under vue-app-3.x.

System Info

Output of npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers:

  System:
    OS: Windows 10 10.0.19042
    CPU: (8) x64 Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz 
    Memory: 16.08 GB / 31.88 GB
  Binaries:
    Node: 14.15.4 - C:\Program Files\nodejs\node.EXE      
    Yarn: 1.22.10 - C:\Program Files\nodejs\yarn.CMD      
    npm: 6.14.10 - C:\Program Files\nodejs\npm.CMD        
  Browsers:
    Chrome: 90.0.4430.93
    Edge: Spartan (44.19041.906.0), Chromium (90.0.818.56)
    Internet Explorer: 11.0.19041.1

Used package manager: yarn

Logs

 ERROR  Failed to compile with 1 errors                                                                                                                                                                        3:22:47 AM
                                                                                                      3:22:47 AM

 error  in ../vue-facebook-login-component-next/dist/vue-facebook-login-component-next.es.js
                                                                                                         s:1
Syntax Error: D:\dev\@vue-facebook-login-component\packages\vue-facebook-login-component-next\.eslintrc.js:1
export default {
^^^^^^

SyntaxError: Unexpected token 'export'
                                                                                                         book-login-component/node_modules/babel-loader/lib!D:/dev/@vue-facebook-login-component/node_modules/cache-loade
                                                                                                         /src/App.vue?vue&type=script&setup=true&lang=js 1:0-92 37:21-34 38:14-20
 @ D:/dev/@vue-facebook-login-component/node_modules/cache-loader/dist/cjs.js??ref--12-0!D:/dev/@vue-facebook-login-component/node_modules/babel-loader/lib!D:/dev/@vue-facebook-login-component/node_modules/cache-loader/dist/cjs.js??ref--0-0!D:/dev/@vue-facebook-login-component/node_modules/vue-loader-v16/dist??ref--0-1!./src/App.vue?vue&type=script&setup=true&lang=js 1:0-92 37:21-34 38:14-20                          ver.js ./src/main.js
 @ ./src/App.vue?vue&type=script&setup=true&lang=js
 @ ./src/App.vue
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://192.168.1.10:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.js

Before submitting the issue, please make sure you do the following

adi518 commented 3 years ago

Nvm, it's not the fault of Vite. My project is running in a monorepo, so I had to set symbolic link resolve to false: https://cli.vuejs.org/guide/troubleshooting.html#symbolic-links-in-node-modules.