Giter VIP home page Giter VIP logo

Comments (7)

stackblitz avatar stackblitz commented on June 27, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

from vite.

bluwy avatar bluwy commented on June 27, 2024

I'm not getting the same error with the repro:

[vite:css] @import must precede all other statements (besides @charset or empty @layer)
3  |  @layer reset, base, variant, state, component;
4  |  
5  |  @import url(./tester.css) layer(base);
   |  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6  |  
7  |  :root {

I get this warning, and the wording is slightly different from what you're showing. Is there some other configuration that causes it?

from vite.

tounsoo avatar tounsoo commented on June 27, 2024

@bluwy Not sure why the wording is different and its just a warning and not an error, but it seems like its the one.

from vite.

tounsoo avatar tounsoo commented on June 27, 2024

Here's the full error when I run Vite build on my local

> tsc && vite build

vite v5.2.13 building for production...
✓ 11 modules transformed.
x Build failed in 730ms
error during build:
[vite:css] @import rules must precede all rules aside from @charset and @layer statements
file: /Users/ben/Projects/pretty3a/lib/ThemeProvider/ThemeProvider.module.css:4:8
SyntaxError: @import rules must precede all rules aside from @charset and @layer statements
 ELIFECYCLE  Command failed with exit code 1.

from vite.

tounsoo avatar tounsoo commented on June 27, 2024

@bluwy Did above help?

from vite.

bluwy avatar bluwy commented on June 27, 2024

Not much unfortunately. I don't know the code that could have trigger the error instead of a warning for me. It's hard to debug from there on.

from vite.

tounsoo avatar tounsoo commented on June 27, 2024

@bluwy The warning is also incorrect. I'm assuming it could be something on my config that is considering that same warning as an error but it looks like its from the same issue where the [vite:css]'s logic considers using @layer above @import to be incorrect, although it says it can be.

Here's my config for reference:

import { resolve } from 'path'
import { defineConfig } from 'vite'
import { libInjectCss } from 'vite-plugin-lib-inject-css'
import dts from 'vite-plugin-dts'
import react from '@vitejs/plugin-react'

const ReactCompilerConfig = {
  sources: (filename: string) => {
    return filename.indexOf('src/path/to/dir') !== -1;
  },
};

export default defineConfig({
  plugins: [
    react({
      babel: {
        plugins: [
          ["babel-plugin-react-compiler", ReactCompilerConfig],
        ],
      },
    }),
    libInjectCss(),
    dts({
      exclude: ['**/*.stories.tsx']
    })
  ],
  css: {
    transformer: 'lightningcss',
  },
  build: {
    sourcemap: true,
    cssMinify: 'lightningcss',
    lib: {
      // Could also be a dictionary or array of multiple entry points
      entry: {
        index: resolve(__dirname, 'lib/main.ts'),
        button: resolve(__dirname, 'lib/Button/index.ts'),
      },
      name: 'MyLib',
      // the proper extensions will be added
      fileName: 'my-lib',
    },
    rollupOptions: {
      // make sure to externalize deps that shouldn't be bundled
      // into your library
      external: ['react'],
      output: {
        // Put chunk files at <output>/chunks
        chunkFileNames: 'chunks/[name].[hash].[format]',
        // Put chunk styles at <output>/assets
        assetFileNames: 'assets/[name][extname]',
        entryFileNames: '[name].[format]',
        // Provide global variables to use in the UMD build
        // for externalized deps
        globals: {
          react: 'React',
        },
      },
    },
  },
  optimizeDeps: {
    exclude: ['storybook']
  }
})

from vite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.