nuxt: tailwind triggers `nuxt.config` import protection
Environment
RootDir: /home/supp/code/test Nuxt project info:
- Operating System:
Linux
- Node Version:
v17.4.0
- Nuxt Version:
3.0.0-27383858.03cc191
- Package Manager:
yarn@1.22.17
- Bundler:
Vite
- User Config:
-
- Runtime Modules:
-
- Build Modules:
-
Reproduction
https://stackblitz.com/edit/github-vaufyy?devtoolsheight=33&file=package.json
Describe the bug
I just create a new clear project with npx nuxi create
and tried to run yarn dev
Errors compilng:
nuxt3/nuxt cannot be imported directly. Instead, import runtime Nuxt composables from #app or #imports. [importing /home/supp/code/test/node_modules/nuxt3/dist/meta/runtime/plugin from virtual:/home/supp/code/test/.nuxt/plugins/server.mjs]
This module cannot be imported in the Vue part of your app. [importing /home/supp/code/test/node_modules/@nuxt/nitro/dist/runtime/app/nitro.client.mjs from virtual:/home/supp/code/test/.nuxt/plugins/server.mjs]
Additional context
No response
Logs
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 31 (18 by maintainers)
Commits related to this issue
- tailwind cssを導入 エラーが出たのでここを参考にして修正した https://github.com/nuxt/framework/issues/2886#issuecomment-1020237093 — committed to s-arikawa/pjm-tools by deleted user 2 years ago
For now, remove the
nuxt.config
scanning from your tailwind config.Do you think you need Tailwind to scan your nuxt.config?
PR send to TailwindLabs docs https://github.com/tailwindlabs/tailwindcss.com/pull/1160
Hey folks! So the main reason we need to include
nuxt.config.{js,ts}
in the list of files that Tailwind CSS scans is because you might be applying Tailwind classes to the<html>
or<body>
elements in this file using thehtmlAttrs
orbodyAttrs
properties available in Vue Meta. By excluding this file, those styles won’t be picked up, and your site will look incorrect.narrowed it down to tailwindcss postcss plugin I thinks, if I comment this out and start the dev environment the error is not present.
With this, no error.
I changed from
tailwind.config.js
totailwind.config.ts
andmodule.exports =
toexport default
.Delete
nuxt.config.{js,ts}
, from content: [] should be :"nuxt3": "^3.0.0-27383920.81ee59c",
ERROR Importing directly from a nuxt.config file is not allowed. Instead, use runtime config or a module. [importing /nuxt.config.ts from index.html]
A point to note on what @rvmourik suggests. I added the
bodyAttrs
property inapp.vue
, the body tailwind styles were not picked up. It works if you create a layout file and add thebodyAttrs
tag in there.~A temporary workaround is to extract the classes into their own file, not ideal but does the job~
Better solution is to define
<head>
inapp.vue
, based on Nuxt 3 migration guide:/cc @danielroe We need to do something for this 😃
No i don’t think so either, I got it from here.
https://tailwindcss.nuxtjs.org/tailwind/config#default-configuration
@pi0 Thanks for the comment. I was able to sort it for now. Just need to delete package-lock.json and just did npm install.
Removing
tailwind.config
fromcontent[]
should fix the issue. Please consider using @nuxtjs/tailwindcss 5 for proper tailwindcss integration with nuxt3.