`?raw` import works in vite (`nuxt dev`) but not in rollup (`nuxt generate`)

As described in the title ?raw works in vite but not in rollup. Simple steps to reproduce:

npx nuxi@latest init raw

add app.css
/* app.css */

.raw {
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    background-color: black;
}


edit app.vue
<!-- app.vue -->

<script setup lang="ts">

import appcss from "~/app.css?raw"

useHead({
    style: [appcss]
})

</script>

<template>
  <div class="raw">
  </div>
</template>


npm run dev works.
npm run generate results in following error.

Nuxt Build Error: Expression expected (Note that you need plugins to import files that are not JavaScript)
file: C:/some/path/raw/app.css?raw?inline&used:3:0
1: /* app.css */
2:
3: .raw {
   ^
4:     width: 100%;
5:     height: 100%;

  at getRollupError (/C:/some/path/raw/node_modules/rollup/dist/es/shared/parseAst.js:375:41)
  at ParseError.initialise (/C:/some/path/raw/node_modules/rollup/dist/es/shared/node-entry.js:11155:28)
  at convertNode (/C:/some/path/raw/node_modules/rollup/dist/es/shared/node-entry.js:12895:10)
  at convertProgram (/C:/some/path/raw/node_modules/rollup/dist/es/shared/node-entry.js:12215:12)
  at Module.setSource (/C:/some/path/raw/node_modules/rollup/dist/es/shared/node-entry.js:14039:24)
  at async ModuleLoader.addModuleSource (/C:/some/path/raw/node_modules/rollup/dist/es/shared/node-entry.js:18689:13)


I'm currently trying to convince rollup to understand the ?raw import like vite does using the following, but I'm not sure how, or if that would even work..
// declarations.d.ts

declare module "*?raw" {
    const src: string
    export default src
}
Was this page helpful?