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

Use import xx from 'xx.css', production environment problem #7281

Closed
7 tasks done
xiaoxian521 opened this issue Mar 11, 2022 · 7 comments · Fixed by #7098
Closed
7 tasks done

Use import xx from 'xx.css', production environment problem #7281

xiaoxian521 opened this issue Mar 11, 2022 · 7 comments · Fixed by #7098

Comments

@xiaoxian521
Copy link

Describe the bug

import xx from 'xx.css'
There is no problem in the development environment, but there is a problem in the production environment.
This problem appeared after vite@2.7.13, there was no problem before.

Here are the key screenshots
Develop(css has content)
image

Production(css content is empty)
image

Reproduction

https://stackblitz.com/edit/vitejs-vite-daffdh?file=src/App.vue

System Info

System:
  OS: macOS 12.2.1
  CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
  Memory: 833.20 MB / 16.00 GB
  Shell: 5.8 - /bin/zsh
Binaries:
  Node: 16.14.0 - /usr/local/bin/node
  Yarn: 1.22.11 - /usr/local/bin/yarn
  npm: 8.3.1 - /usr/local/bin/npm
Browsers:
  Chrome: 99.0.4844.51
  Firefox: 98.0
  Safari: 15.3

Used Package Manager

yarn

Logs

vite:config bundled config file loaded in 173.40ms +0ms
  vite:config using resolved config: {
  vite:config   plugins: [
  vite:config     'alias',
  vite:config     'vite:modulepreload-polyfill',
  vite:config     'vite:resolve',
  vite:config     'vite:html-inline-proxy',
  vite:config     'vite:css',
  vite:config     'vite:esbuild',
  vite:config     'vite:json',
  vite:config     'vite:wasm',
  vite:config     'vite:worker',
  vite:config     'vite:worker-import-meta-url',
  vite:config     'vite:asset',
  vite:config     'vite:vue',
  vite:config     'vite:define',
  vite:config     'vite:css-post',
  vite:config     'vite:watch-package-data',
  vite:config     'vite:build-html',
  vite:config     'commonjs',
  vite:config     'vite:data-uri',
  vite:config     'rollup-plugin-dynamic-import-variables',
  vite:config     'vite:asset-import-meta-url',
  vite:config     'vite:build-import-analysis',
  vite:config     'vite:esbuild-transpile',
  vite:config     'vite:terser',
  vite:config     'vite:reporter',
  vite:config     'vite:load-fallback'
  vite:config   ],
  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     cssTarget: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
  vite:config     sourcemap: false,
  vite:config     rollupOptions: {},
  vite:config     minify: 'esbuild',
  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     reportCompressedSize: true,
  vite:config     chunkSizeWarningLimit: 500,
  vite:config     watch: null,
  vite:config     commonjsOptions: { include: [Array], extensions: [Array] },
  vite:config     dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] }
  vite:config   },
  vite:config   define: { __VUE_OPTIONS_API__: true, __VUE_PROD_DEVTOOLS__: false },
  vite:config   ssr: { external: [ 'vue', '@vue/server-renderer' ] },
  vite:config   configFile: '/home/projects/vitejs-vite-daffdh/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     build: {}
  vite:config   },
  vite:config   root: '/home/projects/vitejs-vite-daffdh',
  vite:config   base: '/',
  vite:config   resolve: { dedupe: undefined, alias: [ [Object], [Object] ] },
  vite:config   publicDir: '/home/projects/vitejs-vite-daffdh/public',
  vite:config   cacheDir: '/home/projects/vitejs-vite-daffdh/node_modules/.vite',
  vite:config   command: 'build',
  vite:config   mode: 'production',
  vite:config   isProduction: true,
  vite:config   server: {
  vite:config     preTransformRequests: true,
  vite:config     fs: { strict: true, allow: [Array], deny: [Array] }
  vite:config   },
  vite:config   preview: {
  vite:config     port: undefined,
  vite:config     strictPort: undefined,
  vite:config     host: undefined,
  vite:config     https: undefined,
  vite:config     open: undefined,
  vite:config     proxy: undefined,
  vite:config     cors: undefined,
  vite:config     headers: undefined
  vite:config   },
  vite:config   env: { BASE_URL: '/', MODE: 'production', DEV: false, PROD: true },
  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   packageCache: Map(0) { set: [Function (anonymous)] },
  vite:config   createResolver: [Function: createResolver],
  vite:config   optimizeDeps: {
  vite:config     esbuildOptions: { keepNames: undefined, preserveSymlinks: undefined }
  vite:config   },
  vite:config   worker: {
  vite:config     format: 'iife',
  vite:config     plugins: [
  vite:config       [Object], [Object], [Object],
  vite:config       [Object], [Object], [Object],
  vite:config       [Object], [Object], [Object],
  vite:config       [Object], [Object], [Object],
  vite:config       [Object], [Object], [Object],
  vite:config       [Object], [Object], [Object],
  vite:config       [Object], [Object], [Object],
  vite:config       [Object], [Object], [Object]
  vite:config     ],
  vite:config     rollupOptions: {}
  vite:config   }
  vite:config } +5ms

Validations

@sapphi-red
Copy link
Member

I digged down this and found that this was happening because tryNodeResolve was stripping ?used. (element-plus has exports field)

This is the same reason for #6725 and it will be fixed with #7098.
It worked when I tried with #7098 actually.

@xiaoxian521
Copy link
Author

xiaoxian521 commented Mar 12, 2022

I digged down this and found that this was happening because tryNodeResolve was stripping ?used. (element-plus has exports field)

This is the same reason for #6725 and it will be fixed with #7098. It worked when I tried with #7098 actually.

Hey, I tested it locally with your code https://github.com/sapphi-red/vite/tree/fix/import-with-query-exports-field and it didn't fix the problem I mentioned

@sapphi-red
Copy link
Member

I tried again and it did work for me.

How did you test it? Did you follow this? Maybe you forgot to run pnpm build in vite repository?

@xiaoxian521
Copy link
Author

xiaoxian521 commented Mar 12, 2022

Just started looking at vite and I'm not sure my steps are correct
pnpm install
pnpm build-vite
cd packages/vite
pnpm link vite --global

@sapphi-red
Copy link
Member

I am not familiar with pnpm link but I think you are using it incorrectly.

I suppose running pnpm link /path/to/vite in your project will work.

@xiaoxian521
Copy link
Author

xiaoxian521 commented Mar 13, 2022

I am not familiar with pnpm link but I think you are using it incorrectly.

I suppose running pnpm link /path/to/vite in your project will work.

you can try: https://vitejs.dev/guide/#using-unreleased-commits

@sapphi-red
Copy link
Member

I tried that now and it did work for me also.

Did you run pnpm link --global vite in your project? (I first forgot to run it.)

@github-actions github-actions bot locked and limited conversation to collaborators Apr 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants