vitejs / vite

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

Cannot import `Vue` (no default export defined) #4681

Closed brendanarnold closed 3 years ago

brendanarnold commented 3 years ago

Describe the bug

After scaffolding a Vue app, trying to do a default import of Vue from a component fails saying that the default export is not defined for 'vue'

image

Reproduction

  1. Scaffold a new vue project using vite cli
  2. Add import Vue from 'vue' to the top of the script area of HelloWorld.vue
  3. Hot reloading fails

example HeloWorld.js

image

System Info

System:
    OS: macOS 11.4
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 56.42 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 15.5.0 - ~/.nvm/versions/node/v15.5.0/bin/node
    npm: 7.3.0 - ~/.nvm/versions/node/v15.5.0/bin/npm
  Browsers:
    Chrome: 92.0.4515.159
    Firefox: 91.0
    Safari: 14.1.1
  npmPackages:
    @vitejs/plugin-vue: ^1.3.0 => 1.4.0 
    vite: ^2.4.4 => 2.5.0 

Used Package Manager

npm

Logs

(base) brendan@MacBook-Pro front-end % npx vite --debug
  vite:config bundled config file loaded in 157ms +0ms
[dotenv][DEBUG] did not match key and value when parsing line 4: 
  vite:config using resolved config: {
  vite:config   plugins: [
  vite:config     'vite:pre-alias',
  vite:config     'alias',
  vite:config     'vite:modulepreload-polyfill',
  vite:config     'vite:resolve',
  vite:config     'vite:html',
  vite:config     'vite:css',
  vite:config     'vite:esbuild',
  vite:config     'vite:json',
  vite:config     'vite:wasm',
  vite:config     'vite:worker',
  vite:config     'vite:asset',
  vite:config     'vite:vue',
  vite:config     'vite:define',
  vite:config     'vite:css-post',
  vite:config     'vite:client-inject',
  vite:config     'vite:import-analysis'
  vite:config   ],
  vite:config   server: { fs: { strict: undefined, allow: [Array] } },
  vite:config   define: { __VUE_OPTIONS_API__: true, __VUE_PROD_DEVTOOLS__: false },
  vite:config   ssr: { external: [ 'vue', '@vue/server-renderer' ] },
  vite:config   configFile: '/Users/brendan/Developer/open-bookmarks/front-end/vite.config.js',
  vite:config   configFileDependencies: [ 'vite.config.js' ],
  vite:config   inlineConfig: {
  vite:config     root: undefined,
  vite:config     base: undefined,
  vite:config     mode: undefined,
  vite:config     configFile: undefined,
  vite:config     logLevel: undefined,
  vite:config     clearScreen: undefined,
  vite:config     server: { fs: [Object] }
  vite:config   },
  vite:config   root: '/Users/brendan/Developer/open-bookmarks/front-end',
  vite:config   base: '/',
  vite:config   resolve: { dedupe: undefined, alias: [ [Object], [Object] ] },
  vite:config   publicDir: '/Users/brendan/Developer/open-bookmarks/front-end/public',
  vite:config   cacheDir: '/Users/brendan/Developer/open-bookmarks/front-end/node_modules/.vite',
  vite:config   command: 'serve',
  vite:config   mode: 'development',
  vite:config   isProduction: false,
  vite:config   build: {
  vite:config     target: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
  vite:config     polyfillModulePreload: true,
  vite:config     outDir: 'dist',
  vite:config     assetsDir: 'assets',
  vite:config     assetsInlineLimit: 4096,
  vite:config     cssCodeSplit: true,
  vite:config     sourcemap: false,
  vite:config     rollupOptions: {},
  vite:config     commonjsOptions: { include: [Array], extensions: [Array] },
  vite:config     dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] },
  vite:config     minify: 'terser',
  vite:config     terserOptions: {},
  vite:config     write: true,
  vite:config     emptyOutDir: null,
  vite:config     manifest: false,
  vite:config     lib: false,
  vite:config     ssr: false,
  vite:config     ssrManifest: false,
  vite:config     brotliSize: true,
  vite:config     chunkSizeWarningLimit: 500,
  vite:config     watch: null
  vite:config   },
  vite:config   env: { BASE_URL: '/', MODE: 'development', DEV: true, PROD: false },
  vite:config   assetsInclude: [Function: assetsInclude],
  vite:config   logger: {
  vite:config     hasWarned: false,
  vite:config     info: [Function: info],
  vite:config     warn: [Function: warn],
  vite:config     warnOnce: [Function: warnOnce],
  vite:config     error: [Function: error],
  vite:config     clearScreen: [Function: clearScreen],
  vite:config     hasErrorLogged: [Function: hasErrorLogged]
  vite:config   },
  vite:config   createResolver: [Function: createResolver],
  vite:config   optimizeDeps: { esbuildOptions: { keepNames: undefined } }
  vite:config } +6ms
  vite:deps Hash is consistent. Skipping. Use --force to override. +0ms

  vite v2.5.0 dev server running at:

  > Local: http://localhost:3000/
  > Network: use `--host` to expose

  ready in 330ms.

  vite:time 1ms   / +0ms
  vite:spa-fallback Rewriting GET / to /index.html +0ms
  vite:time 19ms  /index.html +30ms
  vite:resolve 2ms   /@vite/client -> /Users/brendan/Developer/open-bookmarks/front-end/node_modules/vite/dist/client/client.mjs +0ms
  vite:resolve 0ms   /src/main.js -> /Users/brendan/Developer/open-bookmarks/front-end/src/main.js +4ms
  vite:load 4ms   [fs] /src/main.js +0ms
  vite:resolve 0ms   vue -> /Users/brendan/Developer/open-bookmarks/front-end/node_modules/.vite/vue.js?v=c4954b3a +8ms
  vite:resolve 1ms   /node_modules/.vite/vue.js?v=c4954b3a -> /Users/brendan/Developer/open-bookmarks/front-end/node_modules/.vite/vue.js?v=c4954b3a +1ms
  vite:resolve 0ms   ./App.vue -> /Users/brendan/Developer/open-bookmarks/front-end/src/App.vue +0ms
  vite:resolve 1ms   /src/App.vue -> /Users/brendan/Developer/open-bookmarks/front-end/src/App.vue +1ms
  vite:transform 6ms   /src/main.js +0ms
  vite:time 12ms  /src/main.js +43ms
  vite:load 14ms  [fs] /@vite/client +8ms
  vite:resolve 0ms   @vite/env -> /Users/brendan/Developer/open-bookmarks/front-end/node_modules/vite/dist/client/env.mjs +9ms
  vite:resolve 0ms   /node_modules/vite/dist/client/env.mjs -> /Users/brendan/Developer/open-bookmarks/front-end/node_modules/vite/dist/client/env.mjs +1ms
  vite:transform 6ms   /@vite/client +10ms
  vite:time 28ms  /@vite/client +10ms
  vite:load 2ms   [fs] /node_modules/vite/dist/client/env.mjs +52ms
  vite:rewrite 1ms   [no imports] node_modules/vite/dist/client/env.mjs +0ms
  vite:transform 3ms   /node_modules/vite/dist/client/env.mjs +46ms
  vite:time 6ms   /node_modules/vite/dist/client/env.mjs +46ms
  vite:load 5ms   [fs] /src/App.vue +4ms
  vite:resolve 2ms   ./components/HelloWorld.vue -> /Users/brendan/Developer/open-bookmarks/front-end/src/components/HelloWorld.vue +85ms
  vite:resolve 0ms   /src/components/HelloWorld.vue -> /Users/brendan/Developer/open-bookmarks/front-end/src/components/HelloWorld.vue +0ms
  vite:resolve 0ms   /src/App.vue?vue&type=style&index=0&lang.css -> /Users/brendan/Developer/open-bookmarks/front-end/src/App.vue?vue&type=style&index=0&lang.css +1ms
  vite:hmr [self-accepts] src/App.vue +0ms
  vite:transform 39ms  /src/App.vue +40ms
  vite:time 44ms  /src/App.vue +40ms
  vite:load 0ms   [plugin] /src/App.vue?vue&type=style&index=0&lang.css +47ms
  vite:load 9ms   [fs] /src/components/HelloWorld.vue +7ms
[@vue/compiler-sfc] `defineProps` is a compiler macro and no longer needs to be imported.

  vite:resolve 0ms   /src/components/HelloWorld.vue?vue&type=style&index=0&scoped=true&lang.css -> /Users/brendan/Developer/open-bookmarks/front-end/src/components/HelloWorld.vue?vue&type=style&index=0&scoped=true&lang.css +42ms
  vite:hmr [self-accepts] src/components/HelloWorld.vue +43ms
  vite:transform 27ms  /src/components/HelloWorld.vue +42ms
  vite:time 36ms  /src/components/HelloWorld.vue +42ms
  vite:load 0ms   [plugin] /src/components/HelloWorld.vue?vue&type=style&index=0&scoped=true&lang.css +33ms
  vite:hmr [self-accepts] src/App.vue?vue&type=style&index=0&lang.css +14ms
  vite:transform 48ms  /src/App.vue?vue&type=style&index=0&lang.css +14ms
  vite:time 49ms  /src/App.vue?vue&type=style&index=0&lang.css +14ms
  vite:hmr [self-accepts] src/components/HelloWorld.vue?vue&type=style&index=0&scoped=true&lang.css +8ms
  vite:transform 17ms  /src/components/HelloWorld.vue?vue&type=style&index=0&scoped=true&lang.css +9ms
  vite:time 18ms  /src/components/HelloWorld.vue?vue&type=style&index=0&scoped=true&lang.css +9ms

Validations

haoqunjiang commented 3 years ago

There's no default export in Vue 3. You can use import * as Vue from 'vue', though.