postcss-normalize is overriding my own styles - postcss

I'm trying to use postcss-normalize with PostCSS. Anywhere I place the plugin in the list causes it to override my styles. I have forceImport set to true so I don't need to import it anywhere.
Here's my .postcssrc:
{
"modules": false,
"plugins": {
"postcss-normalize": {
forceImport: true,
},
"postcss-import": {},
"postcss-nesting": {},
"postcss-preset-env": {
"autoprefixer": {
"grid": true
}
},
"postcss-color-mod-function": {},
"postcss-font-magician": [
{
"variants": {
"Open Sans": {
"300": [],
"400": [],
"700": []
},
"Arvo": {
"400": [],
"700": []
}
},
"foundries": ["google"]
}
]
}
}
I'm also using ParcelJS and I import my styles in index.js like so:
import "./css/layout.css"
import "./css/base.css"
import "./css/fonts.css"
import "./css/theme.css"
import header from "./modules/luxbar"
import jumbo from "./modules/jumbo"
import partners from "./modules/partners"
import instructions from "./modules/instructions"
import about from "./modules/about"
import faq from "./modules/faq";
import contact from "./modules/contact"
import testimonials from "./modules/testimonials";
header();
jumbo();
partners();
instructions();
about();
testimonials()
faq('.faq-list');
contact();
A module looks like this:
import $ from 'jquery'
import slick from 'slick-carousel'
import "./base.pcss"
export default () => {
$('.partners__carousel').slick({
autoplay: true,
speed: 300,
arrows: false,
mobileFirst: true,
centerMode: true,
slidesToShow: 2,
slidesToScroll: 1,
buttons: false,
})
}
The CSS is imported in the index.js for that module.
Any ideas how to solve this? Why is normalizer overriding my own styles?

Related

Storybook + Webpack: Can't import the namend export when loading svg files from vite-bundled icon library

We are currently migrating from Webpack to Vite. Therefore we started to switch our icons library to vite - so far this is working fine. This icon library is displayed in a storybook which is currently still bundled with webpack. Build process of the library runs without issues, but as soon as we want to display the icons (SVG-files) in the storybook we receive this warning and no icons are shown:
declaration.d.ts (icon lib)
declare module '*.svg' {
import * as React from 'react';
const ReactComponent: React.FC<React.SVGProps<SVGSVGElement>>;
export default ReactComponent;
}
vite.config.ts (icon lib)
import dts from '#rollup/plugin-typescript';
import svgr from 'vite-plugin-svgr'
import pluginReact from '#vitejs/plugin-react';
import { defineConfig } from 'vite';
import eslint from 'vite-plugin-eslint';
export default defineConfig(() => {
return {
plugins: [
eslint({
fix: true,
exclude: ['**/lib/**'],
}),
pluginReact({
jsxRuntime: 'classic',
}),
svgr(),
],
build: {
emptyOutDir: true,
target: 'esnext',
outDir: 'lib/',
lib: {
entry: './src/index.ts',
name: 'Icons',
fileName: 'index',
formats: ['umd'],
},
rollupOptions: {
plugins: [
dts({
allowSyntheticDefaultImports: true,
exclude: [/node_modules/],
}),
],
external: ['react', 'react-dom', 'styled-components'],
output: {
exports: 'named',
globals: {
react: 'React',
'react-dom': 'ReactDOM',
'styled-components': 'Styled',
},
sourcemap: true,
},
},
},
};
ts.config.json (icon lib)
{
"compilerOptions": {
"declaration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"importHelpers": true,
"isolatedModules": true,
"jsx": "react",
"target": "esnext",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"module": "commonjs",
"moduleResolution": "node",
"noUnusedLocals": true,
"noImplicitAny": true,
"pretty": true,
"removeComments": false,
"sourceMap": true,
"skipLibCheck": true,
"strict": true,
"resolveJsonModule": true
},
"include": ["./src", "declaration.d.ts"]
}
We use a wrapper component called SvgIcon.tsx
import * as React from 'react';
import styled from 'styled-components';
import type { IIconProps } from '../..';
import { StyledSvgIcon } from './SvgIcon.styled';
export type ISvgIconProps = {
component: React.FC<React.SVGProps<SVGSVGElement>>;
} & IIconProps;
export const SvgIcon: React.FC<ISvgIconProps> = (props) => {
const { className, id, size, component: Component } = props;
if (!Component) {
return null;
}
const StyledComponent = styled(Component)`
display: block;
fill: currentColor;
height: 100%;
width: 100%;
`;
return (
<StyledSvgIcon size={size} className={className}>
<StyledComponent id={id} x={'0px'} y={'0px'} width={size} height={size} />
</StyledSvgIcon>
);
};
an example file from the bundled library, IconAdd.js
import * as React from 'react';
import { SvgIcon } from '../../components/SvgIcon';
import { ReactComponent as Add } from '../../../assets/icons/a/Add.svg';
export const IconAdd = (props) => {
return React.createElement(SvgIcon, { ...props, component: Add });
};
For the storysbook we set this value in the webpack.config.js:
{
test: /\.svg?$/,
use: ['#svgr/webpack', 'url-loader'],
},
When I change the import like this:
import ReactComponent from '../../../assets/icons/a/Add.svg';
I receive this error:
Failed to execute 'createElement' on 'Document': The tag name provided ('04516931d13db305ccbc.svg') is not a valid name.

Can't declare interface in React, Typescript, & Vite

I have a project created with React, Typescript & Vite. It gives this error when I declare an interface for a component. I have included the files below that I think will be causing the issue. Let me know if you think anyother file is causing this issue.
[plugin:vite:esbuild] Transform failed with 1 error:
C:/Users/Aqib/Desktop/React/New-Agrod-Frontend/src/components/ui/IconTextField.tsx:3:10: ERROR: Expected ";" but found "Props"
C:/Users/Aqib/Desktop/React/New-Agrod-Frontend/src/components/ui/IconTextField.tsx:4:10
Expected ";" but found "Props"
1 | import RefreshRuntime from "/#react-refresh";let prevRefreshReg;let prevRefreshSig;if (import.meta.hot) { if (!window.__vite_plugin_react_preamble_installed__) { throw new Error( "#vitejs/plugin-react can't detect preamble. Something is wrong. " + "See https://github.com/vitejs/vite-plugin-react/pull/11#discussion_r430879201" ); } prevRefreshReg = window.$RefreshReg$; prevRefreshSig = window.$RefreshSig$; window.$RefreshReg$ = (type, id) => { RefreshRuntime.register(type, "C:/Users/Aqib/Desktop/React/New-Agrod-Frontend/src/components/ui/IconTextField.tsx" + " " + id) }; window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;}import { BaseTextFieldProps, Box, TextField } from '#mui/material';
2 | import { FC, ReactNode } from 'react';
3 | interface Props extends BaseTextFieldProps {
| ^
4 | icon?: ReactNode | ReactNode[];
5 | }
at failureErrorWithLog (C:\Users\Aqib\Desktop\React\New-Agrod-Frontend\node_modules\esbuild\lib\main.js:1604:15)
at C:\Users\Aqib\Desktop\React\New-Agrod-Frontend\node_modules\esbuild\lib\main.js:837:29
at responseCallbacks.<computed> (C:\Users\Aqib\Desktop\React\New-Agrod-Frontend\node_modules\esbuild\lib\main.js:701:9)
at handleIncomingPacket (C:\Users\Aqib\Desktop\React\New-Agrod-Frontend\node_modules\esbuild\lib\main.js:756:9)
at Socket.readFromStdout (C:\Users\Aqib\Desktop\React\New-Agrod-Frontend\node_modules\esbuild\lib\main.js:677:7)
at Socket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Readable.push (node:internal/streams/readable:234:10)
at Pipe.onStreamRead (node:internal/stream_base_commons:190:23
Code causing the bug
import { BaseTextFieldProps, Box, TextField } from '#mui/material'
import { FC, ReactNode } from 'react'
interface Props extends BaseTextFieldProps {
icon?: ReactNode | ReactNode[]
}
const IconTextField: FC<Props> = ({ icon, ...rest }) => {
return (
<Box sx={{ position: 'relative' }}>
<TextField
{...rest}
variant='outlined'
size='small'
InputProps={{
style: {
backgroundColor: 'white',
outline: 'none',
borderRadius: 10,
},
}}
fullWidth
/>
<Box sx={{ position: 'absolute', top: 10, left: -30 }}>{icon}</Box>
</Box>
)
}
export default IconTextField
tsconfig.ts
{
"compilerOptions": {
"baseUrl": ".",
"target": "ESNext",
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"skipLibCheck": true,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"paths": {
"#Pages/*": ["./src/pages/*"],
"#Layout/*": ["./src/layouts/*"],
"#Assets/*": ["./src/assets/*"],
"#Components/*": ["./src/components/*"]
}
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
vite.config.ts
import react from '#vitejs/plugin-react'
import { defineConfig } from 'vite'
import tsconfigPaths from 'vite-tsconfig-paths'
// https://vitejs.dev/config/
export default defineConfig({
esbuild: {
loader: 'jsx',
},
root: './',
build: {
outDir: './build',
},
optimizeDeps: {
esbuildOptions: {
loader: {
'.js': 'jsx',
'.ts': 'tsx',
},
},
},
plugins: [react(), tsconfigPaths()],
})
I tried searching for this bug but couldn't find anything.
If you change the loader it should work
import react from '#vitejs/plugin-react';
import { defineConfig } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';
// https://vitejs.dev/config/
export default defineConfig({
esbuild: {
loader: 'tsx',
},
root: './',
build: {
outDir: './build',
},
optimizeDeps: {
esbuildOptions: {
loader: {
'.js': 'jsx',
'.ts': 'tsx',
},
},
},
plugins: [react(), tsconfigPaths()],
});

sort order import in react using cra

I am trying to update my project's configuration to sort the import order. I'm using create-react-app, and have been following the instructions in this article. Here's what I've done so far:
Run yarn add eslint-plugin-import -D.
Added a .eslintrc.js in src folder of my application.
Added the following configuration as mentioned in the article:
module.exports = {
extends: "react-app",
plugins: ["eslint-plugin-import"],
"import/order": [
"error",
{
groups: ["builtin", "external", "internal"],
pathGroups: [
{
pattern: "react",
group: "external",
position: "before",
},
],
pathGroupsExcludedImportTypes: ["react"],
"newlines-between": "always",
alphabetize: {
order: "asc",
caseInsensitive: true,
},
},
],
};
I've written the following sample component and changed the order of import statements to check if this is working, but when I save the order is not being updated:
Sample.js
import { PropTypes } from "prop-types";
import React from "react";
const Sample = () => <div>Hello</div>;
export default Sample;
Expected after saving
Sample.js
import React from "react";
import { PropTypes } from "prop-types";
const Sample = () => <div>Hello</div>;
export default Sample;
I also tried simple-import-sort, but I don't know how to configure it. How can I configure my project so that import statements are automatically kept in order?
in pathGroups change react to be built, not external:
"pathGroups": [
{
"group": "builtin",
"pattern": "react",
"position": "before"
},
{
"group": "external",
"pattern": "#/**",
"position": "before"
}]

Standardjs no-unused-vars while it's used

In my Typescript React project, I defined:
export type NavState = { mounted: boolean }
and then in my component I used theme like:
import { NavState } from '../../models/nav'
class Nav extends React.Component<any, NavState> {
state: NavState = {
mounted: false
}
}
but I got red underline for NavState in my import and it says:
'NavState' is defined but never used. (no-unused-vars)standard(no-unused-vars)
In my package.json I have this:
"standard": {
"ignore": [
"node_modules/**",
"**/__generated__/"
],
"parser": "#typescript-eslint/parser",
"plugins": [
"#typescript-eslint"
]
}
and my vs-code settings.json is like this:
{
"standard.autoFixOnSave": true,
"standard.enable": true,
"standard.run": "onType",
"standard.validate": [
{ "language": "javascript", "autoFix": true },
{ "language": "javascriptreact", "autoFix": true },
{ "language": "typescript", "autoFix": true },
{ "language": "typescriptreact", "autoFix": true }
]
}
Why Standardjs can't understand that I used a type alias? and how can I fix it?
This should do the trick:
import { NavState } from '../../models/nav' //eslint-disable-line
Notice the comment on the import line.
Check the docs for more.

TSLint - Preventing error: The key is not sorted alphabetically

I'm doing a test app with Ionic2 / Cordova / Typescript / Angular.
I'm using tslint 5.6.0.
I'm using the following module:
https://www.npmjs.com/package/tslint
Focusing on just one file...
when linting the following file:
import { NgModule, ErrorHandler } from "#angular/core";
import { BrowserModule } from "#angular/platform-browser";
import { IonicApp, IonicModule, IonicErrorHandler } from "ionic-angular";
import { MyApp } from "./app.component";
import { AboutPage } from "../pages/about/about";
import { ContactPage } from "../pages/contact/contact";
import { HomePage } from "../pages/home/home";
import { TabsPage } from "../pages/tabs/tabs";
import { StatusBar } from "#ionic-native/status-bar";
import { SplashScreen } from "#ionic-native/splash-screen";
#NgModule( {
declarations: [
MyApp,
AboutPage,
ContactPage,
HomePage,
TabsPage,
],
imports: [
BrowserModule,
IonicModule.forRoot( MyApp ),
],
bootstrap: [ IonicApp ],
entryComponents: [
MyApp,
AboutPage,
ContactPage,
HomePage,
TabsPage,
],
providers: [
StatusBar,
SplashScreen,
{ provide: ErrorHandler, useClass: IonicErrorHandler },
],
})
export class AppModule { }
I get:
The key 'bootstrap' is not sorted alphabetically
RuleFailurePosition { position: 790, lineAndCharacter: { line: 25, character: 4 } }
RuleFailurePosition { position: 799, lineAndCharacter: { line: 25, character: 13 } }
I'm using the following options:
{
"extends": "tslint:recommended",
"rules": {
"no-duplicate-variable": true,
"max-line-length": {
"options": [120]
},
"ordered-imports": false,
"new-parens": true,
"no-arg": true,
"no-bitwise": true,
"no-conditional-assignment": true,
"no-consecutive-blank-lines": false,
"no-console": {
"options": [
"debug",
"info",
"log",
"time",
"timeEnd",
"trace"
]
}
},
"jsRules": {
"max-line-length": {
"options": [120]
}
}
}
What option do I need to configure on TSLint to prevent showing up this error?
The rule failing here seems to be object-literal-sort-keys.
You should be able to disable it in the rules section of your config file by adding:
"object-literal-sort-keys": false
You can find all the tslint rules here.
For anyone coming here who is doing a migration to TypeScript from javascript, or who simply has a mixed codebase of javascript + typescriptm you may to define this rule inside 'jsRules' as well, i.e. to get rid of this error, when you having console statements defined inside javascript (not typescript files).
//tslint.json
{
"extends": ["tslint:recommended", "tslint-react", "tslint-config-prettier"],
"rules": {
"object-literal-sort-keys": false //Disable for typescript
},
"jsRules": {
"object-literal-sort-keys": false //Disable for javascript
}
}

Resources