I'm trying to use the following code:
#apply w-[calc(theme(width.1/3)_-_1rem)] which according to the docs, should work. But every time I try and compile the code I get the following error:
Syntax Error: SyntaxError
<css input> 'width.1 / 3' does not exist in your theme config. 'width' has the following valid keys: '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '14', '16', '20', '24', '28', '32', '36', '40', '44', '48', '52', '56', '60', '64', '72', '80', '96', 'auto', 'px', '0.5', '1.5', '2.5', '3.5', '1/2', '1/3', '2/3', '1/4', '2/4', '3/4', '1/5', '2/5', '3/5', '4/5', '1/6', '2/6', '3/6', '4/6', '5/6', '1/12', '2/12', '3/12', '4/12', '5/12', '6/12', '7/12', '8/12', '9/12', '10/12', '11/12', 'full', 'screen', 'min', 'max', 'fit'
What I'm confused over is that I am using the 1/3 key as the error states, but it seems to be parsed as 1 / 3 which I assume is my problem? I'm using Tailwind 3 with Roots Sage 9.0.10.
Incase it's needed, here's my package.json
{
"name": "sage",
"version": "9.0.10",
"author": "Roots <team#roots.io>",
"homepage": "https://roots.io/sage/",
"private": true,
"repository": {
"type": "git",
"url": "git://github.com/roots/sage.git"
},
"bugs": {
"url": "https://github.com/roots/sage/issues"
},
"licenses": [
{
"type": "MIT",
"url": "http://opensource.org/licenses/MIT"
}
],
"browserslist": [
"last 2 versions",
"android 4",
"opera 12"
],
"scripts": {
"build": "webpack --progress --config resources/assets/build/webpack.config.js",
"build:production": "webpack --env.production --progress --config resources/assets/build/webpack.config.js",
"build:profile": "webpack --progress --profile --json --config resources/assets/build/webpack.config.js",
"start": "webpack --hide-modules --watch --config resources/assets/build/webpack.config.js",
"rmdist": "rimraf dist",
"lint": "npm run -s lint:scripts && npm run -s lint:styles",
"lint:scripts": "eslint resources/assets/scripts resources/assets/build",
"lint:styles": "stylelint \"resources/assets/styles/**/*.{css,sass,scss,sss,less}\"",
"test": "npm run -s lint"
},
"engines": {
"node": ">= 8.0.0"
},
"devDependencies": {
"autoprefixer": "^10.4.0",
"browser-sync": "^2.26.13",
"browsersync-webpack-plugin": "^0.6.0",
"bs-html-injector": "~3.0",
"buble-loader": "^0.4.1",
"cache-loader": "~1.2.5",
"clean-webpack-plugin": "^0.1.18",
"copy-globs-webpack-plugin": "^0.2.0",
"css-loader": "^0.28.11",
"cssnano": "^4.0.5",
"eslint": "~4.19.1",
"eslint-loader": "^4.0.2",
"eslint-plugin-import": "^2.14.0",
"extract-text-webpack-plugin": "~3.0.2",
"file-loader": "^1.1.6",
"friendly-errors-webpack-plugin": "^1.6.1",
"imagemin-mozjpeg": "^9.0.0",
"imagemin-webpack-plugin": "^2.4.2",
"import-glob": "~1.5",
"node-sass": "^5.0.0",
"postcss": "^8.4.5",
"postcss-loader": "^4.0.4",
"postcss-safe-parser": "^5.0.2",
"resolve-url-loader": "~2.3.1",
"rimraf": "^3.0.2",
"sass-loader": "~6.0",
"style-loader": "^0.23.1",
"stylelint": "^13.7.2",
"stylelint-config-standard": "^20.0.0",
"stylelint-webpack-plugin": "^0.10.5",
"tailwindcss": "^3.0.7",
"uglifyjs-webpack-plugin": "^1.3.0",
"url-loader": "^0.6.2",
"webpack": "~3.10.0",
"webpack-assets-manifest": "^1.0.0",
"webpack-dev-middleware": "~2.0.4",
"webpack-hot-middleware": "^2.22.3",
"webpack-merge": "~4.1.4",
"yargs": "^16.1.0"
},
"dependencies": {
"#fancyapps/ui": "^4.0.0-beta.4",
"#fortawesome/fontawesome-free": "^5.15.4",
"aos": "^2.3.4",
"flickity": "^2.3.0",
"flickity-imagesloaded": "^2.0.0",
"jquery": "^3.3.1",
"lodash": "^4.17.21"
},
"stylelint": {
"rules": {}
}
}
It seems Tailwind cannot take a value from config file on the fly (within square brackets in a JIT mode). I see the option to register custom width class within configuration file like
// tailwind.config.js
module.exports = {
theme: {
extend: {
width: {
'custom': "calc( theme('width[1/3]') - 1rem)", // it is important to pass it as a string
}
},
},
}
and use it like
.selector {
#apply w-custom;
}
DEMO
Related
Environment
I am making a website with some administration/hidden for regular user functionality. The application has internationalization. Main stack:
Next
next-i18next
NX
Packages
{
"name": "client",
"version": "1.0.0",
"license": "MIT",
"scripts": {
"serve": "nx serve",
"serve:prod": "nx serve --prod",
"build": "nx build",
"test": "nx test",
"eslint": "eslint --cache",
"prettier": "prettier --check --cache",
"lint": "nx lint",
"format": "nx format:check",
"e2e": "nx e2e",
"affected:e2e": "nx affected --target=e2e",
"affected:lint": "nx affected --target=lint",
"affected:format": "nx affected --target=format",
"affected:test": "nx affected --target=test",
"storybook": "nx storybook",
"storybook:build": "nx build-storybook",
"deploy": "vercel",
"deploy:prod": "vercel --prod",
"prepare": "husky install"
},
"private": true,
"dependencies": {
"#emotion/react": "^11.9.3",
"#emotion/styled": "^11.9.3",
"#fontsource/roboto": "^4.5.7",
"#mui/base": "^5.0.0-alpha.91",
"#mui/icons-material": "^5.8.4",
"#mui/material": "^5.9.2",
"#reduxjs/toolkit": "^1.8.3",
"axios": "^0.27.2",
"formik": "^2.2.9",
"next": "^12.2.3",
"next-i18next": "^11.0.0",
"next-redux-wrapper": "^7.0.5",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-redux": "^8.0.2",
"vercel": "^27.1.3",
"yup": "^0.32.11"
},
"devDependencies": {
"#babel/core": "7.12.13",
"#babel/preset-typescript": "7.12.13",
"#commitlint/cli": "^17.0.3",
"#commitlint/config-conventional": "^17.0.3",
"#next/bundle-analyzer": "^12.2.3",
"#nrwl/cli": "14.4.2",
"#nrwl/cypress": "14.5.1",
"#nrwl/eslint-plugin-nx": "14.4.3",
"#nrwl/express": "^14.4.3",
"#nrwl/jest": "14.5.1",
"#nrwl/linter": "14.4.2",
"#nrwl/next": "14.4.0",
"#nrwl/node": "14.4.0",
"#nrwl/react": "14.4.2",
"#nrwl/storybook": "14.4.2",
"#nrwl/web": "14.4.3",
"#nrwl/workspace": "14.4.2",
"#storybook/addon-essentials": "~6.5.9",
"#storybook/builder-webpack5": "~6.5.9",
"#storybook/core-server": "~6.5.9",
"#storybook/manager-webpack5": "~6.5.9",
"#storybook/react": "~6.5.9",
"#svgr/webpack": "^5.4.0",
"#testing-library/cypress": "^8.0.3",
"#testing-library/jest-dom": "^5.16.4",
"#testing-library/react": "13.3.0",
"#types/express": "4.17.13",
"#types/jest": "27.4.1",
"#types/node": "18.0.4",
"#types/react": "18.0.15",
"#types/react-dom": "18.0.5",
"#typescript-eslint/eslint-plugin": "^5.30.3",
"#typescript-eslint/parser": "^5.30.3",
"babel-jest": "27.5.1",
"babel-loader": "8.1.0",
"core-js": "^3.6.5",
"cypress": "^10.3.0",
"cypress-real-events": "^1.7.1",
"cypress-web-vitals": "^2.0.0",
"eslint": "8.2.0",
"eslint-config-airbnb": "19.0.4",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-config-next": "12.1.6",
"eslint-config-prettier": "8.1.0",
"eslint-plugin-cypress": "^2.10.3",
"eslint-plugin-import": "2.25.3",
"eslint-plugin-jsx-a11y": "6.5.1",
"eslint-plugin-react": "7.30.1",
"eslint-plugin-react-hooks": "4.6.0",
"husky": "^8.0.1",
"jest": "27.5.1",
"lint-staged": "^13.0.3",
"nx": "14.5.1",
"prettier": "^2.7.1",
"react-test-renderer": "18.2.0",
"regenerator-runtime": "0.13.7",
"ts-jest": "27.1.4",
"ts-node": "~10.8.0",
"tslib": "^2.3.0",
"typescript": "~4.7.2",
"url-loader": "^3.0.0"
}
}
Problem
The problem is that raw locales in the .json format are accessible by GET requests. For example, I can visit http://localhost/locales/en/common.json and get:
{
"email": {
"length": {
"short": "Email is too short",
"long": "Email is too long"
},
"format": "Email format is wrong",
"required": "Email is required"
},
"password": {
"length": {
"short": "Password is too short",
"long": "Password is too long"
},
"format": "Password format is wrong",
"required": "Password is required"
}
}
The locales are not placed in the public directory during development and next-i18next is configured for another locales path by its next-i18next.config.js.
I18n config
const path = require('path');
module.exports = {
debug: process.env.NODE_ENV === 'development',
i18n: {
locales: ['en', 'uk'],
defaultLocale: 'en',
},
localePath: path.resolve('./apps/client/locales'),
};
Question
I think that users can guess these paths and get some sensitive information. Are there any ways to make them accessible only for Next, but not for the public? Maybe I should change my way of localization at all, shouldn't I?
next-translate looks like the library with different internationalization logic, which resolved my problem.
I tried to build my Next.js Commerce with Swell storefront integration. It uses turbo and the result of build is
ERROR: task public not found in turbo pipeline in "turbo.json". Are you sure you added it?
I looked at configuration options of turbo documentation, but I don't have any idea where to put public in turbo.json. I tweaked around with it for a while, but no chance to fix it myself.
/turbo.json:
{
"baseBranch": "origin/main",
"pipeline": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**"]
},
"next-commerce#build": {
"dependsOn": [
"^build",
"$COMMERCE_PROVIDER",
"$BIGCOMMERCE_STOREFRONT_API_URL",
"$NEXT_PUBLIC_SHOPIFY_STORE_DOMAIN",
"$NEXT_PUBLIC_SWELL_STORE_ID"
],
"outputs": [".next/**"]
},
"test": {
"dependsOn": ["^build"],
"outputs": []
},
"lint": {
"outputs": []
},
"prettier-fix": {
"outputs": []
},
"dev": {
"cache": false
},
"start": {
"cache": false
},
"types": {
"outputs": ["dist/**/*.d.ts"]
}
}
}
/package.json
{
"name": "commerce",
"license": "MIT",
"private": true,
"workspaces": [
"site",
"packages/*"
],
"scripts": {
"build": "turbo run build --filter=next-commerce..." ,
"dev": "turbo run dev",
"start": "turbo run start",
"types": "turbo run types",
"prettier-fix": "prettier --write ."
},
"devDependencies": {
"husky": "^7.0.4",
"prettier": "^2.5.1",
"turbo": "^1.2.16"
},
"husky": {
"hooks": {
"pre-commit": "turbo run lint"
}
},
"packageManager": "yarn#1.22.17"
}
/site/package.json
{
"name": "next-commerce",
"version": "0.0.1",
"license": "MIT",
"scripts": {
"dev": "next dev",
"build": "next build public",
"start": "next start",
"analyze": "BUNDLE_ANALYZE=both next build",
"lint": "next lint",
"prettier-fix": "prettier --write .",
"find:unused": "npx next-unused"
},
"sideEffects": false,
"dependencies": {
"#radix-ui/react-dropdown-menu": "^0.1.6",
"#react-spring/web": "^9.4.1",
"#vercel/commerce": "^0.0.1",
"#vercel/commerce-bigcommerce": "^0.0.1",
"#vercel/commerce-commercejs": "^0.0.1",
"#vercel/commerce-kibocommerce": "^0.0.1",
"#vercel/commerce-local": "^0.0.1",
"#vercel/commerce-ordercloud": "^0.0.1",
"#vercel/commerce-saleor": "^0.0.1",
"#vercel/commerce-shopify": "^0.0.1",
"#vercel/commerce-spree": "^0.0.1",
"#vercel/commerce-swell": "^0.0.1",
"#vercel/commerce-vendure": "^0.0.1",
"autoprefixer": "^10.4.2",
"body-scroll-lock": "^4.0.0-beta.0",
"clsx": "^1.1.1",
"email-validator": "^2.0.4",
"js-cookie": "^3.0.1",
"keen-slider": "^6.6.3",
"lodash.random": "^3.2.0",
"lodash.throttle": "^4.1.1",
"next": "^12.0.8",
"next-themes": "^0.0.15",
"postcss": "^8.3.5",
"postcss-nesting": "^8.0.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-fast-marquee": "^1.3.1",
"react-merge-refs": "^1.1.0",
"react-use-measure": "^2.1.1",
"tabbable": "^5.2.1",
"tailwindcss": "^3.0.13"
},
"devDependencies": {
"#next/bundle-analyzer": "^12.0.8",
"#types/body-scroll-lock": "^3.1.0",
"#types/js-cookie": "^3.0.1",
"#types/lodash.random": "^3.2.6",
"#types/lodash.throttle": "^4.1.6",
"#types/node": "^17.0.8",
"#types/react": "^17.0.38",
"eslint": "^8.6.0",
"eslint-config-next": "^12.0.8",
"eslint-config-prettier": "^8.3.0",
"lint-staged": "^12.1.7",
"postcss-flexbugs-fixes": "^5.0.2",
"postcss-preset-env": "^7.2.3",
"prettier": "^2.5.1",
"typescript": "4.3.4"
},
"lint-staged": {
"**/*.{js,jsx,ts,tsx}": [
"eslint",
"prettier --write",
"git add"
],
"**/*.{md,mdx,json}": [
"prettier --write",
"git add"
]
},
"next-unused": {
"alias": {
"#lib/*": [
"lib/*"
],
"#assets/*": [
"assets/*"
],
"#config/*": [
"config/*"
],
"#components/*": [
"components/*"
],
"#utils/*": [
"utils/*"
]
},
"debug": true,
"include": [
"components",
"lib",
"pages"
],
"exclude": [],
"entrypoints": [
"pages"
]
}
}
I am trying to use Grunt PostCSS Autoprefixer but it keeps saying that it is not a PostCSS plugin:
package.json
{
"name": "test",
"version": "0.2.0",
"description": "test",
"keywords": [
""
],
"author": "",
"license": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"cssmin": "^0.4.3",
"cssnano": "^5.0.6",
"grunt": "^1.4.1",
"grunt-babel": "^8.0.0",
"grunt-contrib-cssmin": "^4.0.0",
"grunt-contrib-uglify": "^5.0.1",
"grunt-contrib-watch": "^1.1.0"
},
"devDependencies": {
"#babel/core": "^7.14.5",
"#babel/preset-env": "^7.14.5",
"autoprefixer": "^10.2.6",
"grunt-postcss": "^0.9.0",
"grunt-postcss-import": "0.0.1",
"grunt-prettify": "^0.4.0",
"postcss": "^8.3.2"
}
}
Gruntfile.js
postcss: {
options: {
map: {
inline: false,
annotation: 'dist/css/maps/'
},
processors: [
// require('pixrem')(),
require('autoprefixer')(),
//require('cssnano')()
]
},
dist: {
src: 'dist/css/bundle.css'
}
},
I made sure to first remove the grunt-autoprefixer and install autoprefixer which should be a postcss plugin.
It turns out it was just a version compatibility issue. I simply changed:
"autoprefixer": "^10.2.6",
with:
"autoprefixer": "^9.7.4",
I've made a project based on react and when I open my react website on the localhost, all the css properties doesn't show up. Rest other functionalities are working as usual and all the react logic, but the css effect is missing. It looks plain. I'm showing the image of localhost for example.
And this is my package.json file
{
"name": "test",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.11.4",
"#testing-library/react": "^11.1.0",
"#testing-library/user-event": "^12.1.10",
"axios": "^0.21.1",
"node-sass": "^4.14.1",
"react": "^17.0.1",
"react-avatar-edit": "^0.9.0",
"react-css-modules": "^4.7.11",
"react-dom": "^17.0.1",
"react-images": "^1.1.7",
"react-modal": "^3.12.1",
"react-redux": "^7.2.2",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.1",
"react-scripts-scss-ts": "^2.17.1",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0",
"web-vitals": "^0.2.4",
"webpack": "^4.44.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"#types/react": "^17.0.0",
"sass": "^1.32.4",
"sass-loader": "^10.1.1"
}
}
Please help me locate the error
Hello guys can anybody help with Nextjs v10 build ? it builds without styles :|
here is my package.json and next.config.js
I import all styles in _app.js, it also comes in chrome network -> preview without styles
On vercel everything is ok, but when i try to build on my computer, it's without styles :|
**
next.config.js
**
module.exports = {
images: {
domains: ['localhost','assets.vercel.com','via.placeholder.com','mine-front-new.vercel.app'],
},
}
package.json
{
"name": "mine",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "next",
"build": "next build",
"start": "next start",
"prod:build": "SET NODE_ENV=production && next build && next export",
"export": "next build && next export"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"#fortawesome/fontawesome-free": "^5.13.1",
"#material-ui/core": "^4.11.0",
"#material-ui/icons": "^4.9.1",
"#material-ui/lab": "^4.0.0-alpha.57",
"add": "^2.0.6",
"axios": "^0.19.2",
"chart.js": "^2.9.3",
"date-fns": "^2.16.1",
"draft-js": "^0.11.7",
"es6-shim": "^0.35.6",
"js-cookie": "^2.2.1",
"jwt-decode": "^3.0.0",
"moment": "^2.27.0",
"next": "10.0.0",
"react": "17.0.1",
"react-chartjs-2": "^2.9.0",
"react-dom": "17.0.1",
"react-facebook": "^8.1.4",
"react-lottie": "^1.2.3",
"react-transition-group": "^4.4.1",
"yarn": "^1.22.10"
},
"devDependencies": {
"#types/cookie": "^0.4.0",
"clsx": "^1.1.1",
"cookie": "^0.4.1",
"prop-types": "^15.7.2",
"react-date-range": "^1.0.3",
"react-reveal": "^1.2.2",
"react-slick": "^0.26.1",
"react-toastify": "^6.0.8",
"slick-carousel": "^1.8.1",
"sweetalert2": "^9.15.2"
}
}
Make sure u use appropriate css loaders. I faced the same issue and resolved using this,
loaders: ['style-loader', 'css-loader', 'less-loader']
My next.config.js
module.exports = withImages({
target: 'serverless',
webpack: function (config, { webpack }) {
config.module.rules.push({
test: /\.(eot|svg|gif|md)$/,
loaders: ['style-loader', 'css-loader', 'less-loader']
})
return config
},
})