Referencing Default Colors When Customizing Tailwind CSS - tailwind-css

I am trying to extend the color palette of tailwind css using their tailwind.config.js file. My goal is to create a set of primary and secondary colors that I can use when styling my site. I want to do so by referencing already existing colors from the default tailwind theme. Based on the documentation, I though the following would work (but it does not):
const defaultTheme = require('tailwindcss/defaultTheme')
module.exports = {
theme: {
extend: {
colors: {
primary: {
light: defaultTheme.colors['400'],
default: defaultTheme.colors['500'],
dark: defaultTheme.colors['600']
}
}
}
},
variants: {},
plugins: []
}
Here is the problem, in my style sheet, I have the following:
.navbar {
...
#apply bg-primary-dark;
...
}
My expectation is that this would work - but it doesn't. I get an error (see below).
Any idea what I am doing wrong and how I can fix it?
Thanks.
ERROR MESSAGE
> startup-reporter#1.0.0 dev C:\laragon\www\sage\wp-content\themes\startup-reporter
> npm run development
> startup-reporter#1.0.0 development C:\laragon\www\sage\wp-content\themes\startup-reporter
> cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
98% after emitting SizeLimitsPlugin
ERROR Failed to compile with 2 errors 9:18:34 PM
error in ./src/assets/css/style.css
Syntax Error: ModuleBuildError: Module build failed (from ./node_modules/postcss-loader/src/index.js):SyntaxError
(9:3) `#apply` cannot be used with `.bg-primary-dark` because `.bg-primary-dark` either cannot be found, or its actual definition includes a pseudo-selector like :hover, :active, etc. If you're sure that
`.bg-primary-dark` exists, make sure that any `#import` statements are being properly processed *before* Tailwind CSS sees your CSS, as `#apply` can only be used for classes in the same CSS tree.
7 | .navbar {
8 | width: 100%;
> 9 | #apply bg-primary-dark;
| ^
10 | #apply flex flex-wrap relative;
11 | #apply font-semibold;
error in ./src/assets/css/style.css
Syntax Error: SyntaxError
(9:3) `#apply` cannot be used with `.bg-primary-dark` because `.bg-primary-dark` either cannot be found, or its actual definition includes a pseudo-selector like :hover, :active, etc. If you're sure that
`.bg-primary-dark` exists, make sure that any `#import` statements are being properly processed *before* Tailwind CSS sees your CSS, as `#apply` can only be used for classes in the same CSS tree.
7 | .navbar {
8 | width: 100%;
> 9 | #apply bg-primary-dark;
| ^
10 | #apply flex flex-wrap relative;
11 | #apply font-semibold;
# ./src/assets/css/style.css 2:14-150
ERROR in ./src/assets/css/style.css
Module build failed (from ./node_modules/css-loader/index.js):
ModuleBuildError: Module build failed (from ./node_modules/postcss-loader/src/index.js):
SyntaxError
(9:3) `#apply` cannot be used with `.bg-primary-dark` because `.bg-primary-dark` either cannot be found, or its actual definition includes a pseudo-selector like :hover, :active, etc. If you're sure that
`.bg-primary-dark` exists, make sure that any `#import` statements are being properly processed *before* Tailwind CSS sees your CSS, as `#apply` can only be used for classes in the same CSS tree.
7 | .navbar {
8 | width: 100%;
> 9 | #apply bg-primary-dark;
| ^
10 | #apply flex flex-wrap relative;
11 | #apply font-semibold;
at C:\laragon\www\sage\wp-content\themes\startup-reporter\node_modules\webpack\lib\NormalModule.js:316:20
at C:\laragon\www\sage\wp-content\themes\startup-reporter\node_modules\loader-runner\lib\LoaderRunner.js:367:11
at C:\laragon\www\sage\wp-content\themes\startup-reporter\node_modules\loader-runner\lib\LoaderRunner.js:233:18
at context.callback (C:\laragon\www\sage\wp-content\themes\startup-reporter\node_modules\loader-runner\lib\LoaderRunner.js:111:13)
at C:\laragon\www\sage\wp-content\themes\startup-reporter\node_modules\postcss-loader\src\index.js:207:9
at processTicksAndRejections (internal/process/task_queues.js:93:5)
# ./src/assets/css/style.css
ERROR in ./src/assets/css/style.css (./node_modules/css-loader??ref--8-2!./node_modules/postcss-loader/src??postcss0!./src/assets/css/style.css)
Module build failed (from ./node_modules/postcss-loader/src/index.js):
SyntaxError
(9:3) `#apply` cannot be used with `.bg-primary-dark` because `.bg-primary-dark` either cannot be found, or its actual definition includes a pseudo-selector like :hover, :active, etc. If you're sure that
`.bg-primary-dark` exists, make sure that any `#import` statements are being properly processed *before* Tailwind CSS sees your CSS, as `#apply` can only be used for classes in the same CSS tree.
7 | .navbar {
8 | width: 100%;
> 9 | #apply bg-primary-dark;
| ^
10 | #apply flex flex-wrap relative;
11 | #apply font-semibold;
# ./src/assets/css/style.css 2:14-150
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! startup-reporter#1.0.0 development: `cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the startup-reporter#1.0.0 development script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\moshe\AppData\Roaming\npm-cache\_logs\2020-03-08T19_18_34_238Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! startup-reporter#1.0.0 dev: `npm run development`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the startup-reporter#1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\moshe\AppData\Roaming\npm-cache\_logs\2020-03-08T19_18_34_295Z-debug.log
PS C:\laragon\www\sage\wp-content\themes\startup-reporter>

I had the same issue with newer version currently is 2, my stub file was working fine for the old version;
After investigating it turns out the default config doesn't hold the full color platte anymore instead of inheriting from:
const { colors } = require('tailwindcss/defaultTheme')
try to export the whole colors.js file like:
const colors = require('tailwindcss/colors')
and that worked well for me.

Related

build with multi page don't work with vite 2.6 and vue 3.2

I made a simple multipage app with vue 3.2 and vite 2.6
|-src
|---main.js
|-package.json
|-vite.config.js
|-index.html
|-validation_password.html
But when I want to build it: vite build only the index page (and not the validation-password).
I tried to modify my vite.config.js with rollup Options like here :
const { resolve } = require('path')
module.exports = defineConfig({
build: {
rollupOptions: {
input: {
main: resolve(__dirname, 'index.html'),
valpass: resolve(__dirname, 'validation_password.html')
}
}
}
})
the build failed. and i have this error in my terminal:
[rollup-plugin-dynamic-import-variables] Unexpected token (1:0)
file: C:/wamp64/www/IMB/VueJS/vuejs/src/PassVal.vue:1:0
error during build:
SyntaxError: Unexpected token (1:0)
at Parser.pp$5.raise (C:\wamp64\www\IMB\VueJS\vuejs\node_modules\rollup\dist\shared\rollup.js:19495:13)
at Parser.pp.unexpected (C:\wamp64\www\IMB\VueJS\vuejs\node_modules\rollup\dist\shared\rollup.js:16820:8)
at Parser.pp$4.parseExprAtom (C:\wamp64\www\IMB\VueJS\vuejs\node_modules\rollup\dist\shared\rollup.js:18870:10)
at Parser.pp$4.parseExprSubscripts (C:\wamp64\www\IMB\VueJS\vuejs\node_modules\rollup\dist\shared\rollup.js:18662:19)
at Parser.pp$4.parseMaybeUnary (C:\wamp64\www\IMB\VueJS\vuejs\node_modules\rollup\dist\shared\rollup.js:18628:17)
at Parser.pp$4.parseExprOps (C:\wamp64\www\IMB\VueJS\vuejs\node_modules\rollup\dist\shared\rollup.js:18561:19)
at Parser.pp$4.parseMaybeConditional (C:\wamp64\www\IMB\VueJS\vuejs\node_modules\rollup\dist\shared\rollup.js:18544:19)
at Parser.pp$4.parseMaybeAssign (C:\wamp64\www\IMB\VueJS\vuejs\node_modules\rollup\dist\shared\rollup.js:18512:19)
at Parser.pp$4.parseExpression (C:\wamp64\www\IMB\VueJS\vuejs\node_modules\rollup\dist\shared\rollup.js:18476:19)
at Parser.pp$1.parseStatement (C:\wamp64\www\IMB\VueJS\vuejs\node_modules\rollup\dist\shared\rollup.js:17010:45)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! components-portail-math#0.0.1 build: `vite build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the components-portail-math#0.0.1 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\willb\AppData\Roaming\npm-cache\_logs\2021-10-07T14_34_53_913Z-debug.log
My PassVal.vue file break no worries locally.
I don't understand. I'm following the doc.
I used Vue Router(I didn't know) to solve my problem.

Deploying NextJS to Vercel failed

I am trying to deploy an app to Vercel, and getting this error at build
14:13:58.168 Cloning github.com/ChrisB007/moodflics (Branch: main, Commit: 7a2acfe)
14:13:58.575 Cloning completed: 406.06ms
14:13:58.624 Analyzing source code...
14:13:59.946 Installing build runtime...
14:14:03.139 Build runtime installed: 3.193s
14:14:07.055 Build cache not provided
14:14:08.517 Installing dependencies...
14:14:09.142 npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion#1, but package-lock.json was generated for lockfileVersion#2. I'll try to do my best with it!
14:14:23.664 npm WARN moodflics#0.1.0 No repository field.
14:14:23.676 npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents#2.3.2 (node_modules/fsevents):
14:14:23.677 npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents#2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
14:14:23.681 added 387 packages from 281 contributors in 14.582s
14:14:23.836 62 packages are looking for funding
14:14:23.836 run `npm fund` for details
14:14:23.861 Detected Next.js version: 10.2.0
14:14:23.864 Running "npm run build"
14:14:24.144 > moodflics#0.1.0 build /vercel/path0
14:14:24.144 > next build
14:14:24.557 warn - React 17.0.1 or newer will be required to leverage all of the upcoming features in Next.js 11. Read more: https://nextjs.org/docs/messages/react-version
14:14:24.912 info - Using webpack 5. Reason: no custom webpack configuration in next.config.js https://nextjs.org/docs/messages/webpack5
14:14:25.052 info - Checking validity of types...
14:14:25.068 Attention: Next.js now collects completely anonymous telemetry regarding usage.
14:14:25.068 This information is used to shape Next.js' roadmap and prioritize features.
14:14:25.068 You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
14:14:25.068 https://nextjs.org/telemetry
14:14:25.123 info - Creating an optimized production build...
14:14:29.905 Failed to compile.
14:14:29.906 ModuleNotFoundError: Module not found: Error: Can't resolve 'next-auth/client' in '/vercel/path0/pages'
14:14:29.906 > Build error occurred
14:14:29.907 Error: > Build failed because of webpack errors
14:14:29.907 at /vercel/path0/node_modules/next/dist/build/index.js:17:924
14:14:29.907 at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/telemetry/trace/trace.js:6:584)
14:14:29.946 npm ERR! code ELIFECYCLE
14:14:29.947 npm ERR! errno 1
14:14:29.951 npm ERR! moodflics#0.1.0 build: `next build`
14:14:29.951 npm ERR! Exit status 1
14:14:29.951 npm ERR!
14:14:29.951 npm ERR! Failed at the moodflics#0.1.0 build script.
14:14:29.951 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
14:14:29.959 npm ERR! A complete log of this run can be found in:
14:14:29.959 npm ERR! /vercel/.npm/_logs/2021-05-10T18_14_29_952Z-debug.log
14:14:29.972 Error: Command "npm run build" exited with 1
Everything seems to be working fine locally, but when I tried deploying it to Vercel I got the above error message. Can you tell me how to fix it?
Sometimes Vercel acts wired that my codes run locally(npm run dev) but fail after upload. This happens when I use Github automatic deployment, i.e. I directly push to my Github repo then Vercel automatically build and update.
However, using Vercel CLI solved my problem. run vercel for preview then vercel --prod for deployment in production
It can't resolve next-auth/client
ModuleNotFoundError: Module not found: Error: Can't resolve 'next-auth/client' in '/vercel/path0/pages'
Ensure that next-auth is properly installed as a dependency and not a dev dependency. Also upgrade your version of react, it's throwing a warning about it not being 17.01 or higher. If you are using typescript, try module augmentation via the next-auth namespace as indicated in their documentation for typescript namespaces. For example, an #/types/next.d.ts file and an #/types/next-auth.d.ts file for module augmentation.
Locally, I use nextauth as well, and have the following in my #/types/next.d.ts file:
import type { NextComponentType, NextPageContext } from 'next';
import type { Session } from 'next-auth';
import type { Router } from 'next/router';
declare module 'next/app' {
type AppProps<P = Record<string, unknown>> = {
Component: NextComponentType<NextPageContext, any, P>;
router: Router;
__N_SSG?: boolean;
__N_SSP?: boolean;
pageProps: P & {
/** Initial session passed in from getServerSideProps or getInitialProps */
session?: Session;
};
};
}
As for the contents of my #/types/next-auth.d.ts file, it's for a custom headless wordpress auth flow, but you can customize the Session/User interfaces regardless of whether you're using a custom approach or not
import NextAuth, { User } from 'next-auth';
import { JWT } from 'next-auth/jwt';
import { WordpressUserPartialFragment } from '../graphql/generated/graphql';
declare module 'next-auth' {
interface Session extends WordpressUserPartialFragment {
response: {
accessToken: string;
id: string;
avatar: {
url: string;
};
description: string | null;
slug: string;
username: string;
email: string;
firstName: string;
lastName: string;
token_exp: string;
refresh_token: string;
locale: string;
};
}
}
Delete node_modules and run yarn install.
Then do yarn build.
If you use npm then do npm i and npm run build instead of yarn install and yarn build.
Then deploy
Check .vercelignore file for folders/files you are missing.
In my case, I have included folder and forgot.
Also double check what source files got synced to vercel, under project deployments, source tab.

Runtime error when trying to use css modules with react and snowpack

I have an issue when trying yo setup css modules with react and snowpack. Here is how to reproduce the issue:
"snowpack": "^2.17.0",
"#snowpack/plugin-sass": "^1.1.1",
Setup a new app using npx
npx create-snowpack-app snowpack --template #snowpack/app-template-react-typescript
npm install #snowpack/plugin-sass --save-dev
Add sass file
app.sass
.test
width: 30px
height: 30px
background: red
App.tsx
import styles from './app.sass'
<div className={styles.test}/>
Snowpack devOptions
port: 8005,
open: 'none',
bundle: false,
out: 'dist'
Snowpack plugins
'#snowpack/plugin-react-refresh',
'#snowpack/plugin-dotenv',
'#snowpack/plugin-typescript',
'#snowpack/plugin-webpack',
'#snowpack/plugin-sass',
Run snowpack dev
npm start => snowpack dev
Error
SyntaxError: The requested module './app.css.proxy.js' does not provide an export named 'default'
The solution is to rename app.sass to app.module.sass
Snowpack supports CSS Modules using the [name].module.css naming convention. CSS Modules work just like normal CSS imports, but with a special default styles export that maps your original classnames to unique identifiers.
https://www.snowpack.dev/#import-css-modules

Angular ERROR: PostCSS received undefined instead of CSS string

Trying to build an Angular project and I'm getting the errors below. This project built fine last week. I made some changes to other projects that use the Dlls from this project, but no changes to this project. I already spent a lot of time troubleshooting it with no luck and appreciate any help.
ERROR: PostCSS received undefined instead of CSS string
An unhandled exception occurred: PostCSS received undefined instead of CSS string
This can sometimes happen if node-sass was compiled for a different version of Node.js than you're currently running (ie if you've recently changed your Node.js version). You can fix that with:
npm rebuild node-sass
if you are using webpack, and trying to use sass-loader, also add sass
I had this same issue when attempting to test an Angular library, and the issue was I had [``] instead of [] in the styles property of my component metadata.
Wrong
#Component({
selector: 'my-input',
template: `
<input
... />
`,
styles: [``],
Right
#Component({
selector: 'my-input',
template: `
<input
... />
`,
styles: [],
I had similar problem. I was trying to build an angular library and the message below appeared:
Building Angular Package
------------------------------------------------------------------------------
Building entry point 'library-name'
------------------------------------------------------------------------------
Compiling TypeScript sources through ngc
ERROR: PostCSS received undefined instead of CSS string
An unhandled exception occurred: PostCSS received undefined instead of CSS string
See "/tmp/ng-itlEgm/angular-errors.log" for further details.
[12:03:38] 'compile' errored after 17 s
[12:03:38] Error: Command `ng build library-name --prod` exited with code 127
at ChildProcess.handleSubShellExit (/node_modules/gulp-run/command.js:166:13)
at Object.onceWrapper (events.js:422:26)
at ChildProcess.emit (events.js:315:20)
at ChildProcess.EventEmitter.emit (domain.js:505:15)
at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
[12:03:38] 'build' errored after 17 s
I was using gulp-run to execute the command ng build library-name --prod. But, executing the command ng build library-name --prod directly on the terminal, the log error was smaller, but similar too.
The problem was in one component. The component had one styleURL (Angular component decorator), like this:
...component.css
but, the library uses scss. So, I changed the path to:
...component.scss
and I executed the command 'ng build library-name --prod'. So, the error didn't appear again.
I was using NVM v0.35.2 (allow to have more than one NodeJS version installed in my machine); NodeJS v12.18.2; Ubuntu x64 18.0.4 LTS and Angular CLI 9.1.9.
I faced the same situation now and the command that helped me is -
npm i node-sass -D
Check the node version, see if the version of node changes cause this problem. I use node version 16.14.2 which occured this error, after switch to 12.16.1 it works well. Just check your node-sass and node version will find a way out.
This can happen due to change in version of node. I had same issue with a NUXT app. What I did was
using yarn, in the root directory of your project, run yarn. But if you're using npm run npm install
start your project again.

Install Bootstrap 4 on Laravel 5.3

I have followed the following instruction in order to install Bootstrap 4 alpha on my Laravel 5.3 project, but it pops up errors.
Steps to install:
npm install bootstrap#4.0.0-alpha.3 --save-dev
resources/assets/sass/app.scss
// change this line
#import "node_modules/bootstrap-sass/assets/stylesheets/bootstrap";
//to this
#import "node_modules/bootstrap/scss/bootstrap";
resources/assets/sass/variables.scss
// change this line to rem or em units, or just remove it entirely
$font-size-base: 14px;
resources/assets/js/bootstrap.js
// change this line
require('bootstrap-sass');
// to this
require('bootstrap');
I got the following error
ERROR in ./resources/assets/js/bootstrap.js Module not found: Error:
Can't resolve 'bootstrap' in
'C:\xampp\htdocs\soyegg\resources\assets\js' #
./resources/assets/js/bootstrap.js 11:0-20 #
./resources/assets/js/app.js
And I refresh my page and got this for console log
Uncaught Error: Cannot find module "bootstrap"
at webpackMissingModule (eval at (app.js:89), :11:65)
at eval (eval at (app.js:89), :11:151)
at Object. (app.js:89)
at webpack_require (app.js:20)
at eval (eval at (app.js:228), :1:1)
at Object. (app.js:228)
at webpack_require (app.js:20)
at app.js:64
at app.js:67
Please help. Thanks
Not sure why, but I eventually try to reinstall alpha.5 by npm install bootstrap#4.0.0-alpha.5 --save-dev and it fixed the problem.

Resources