I'm using facebook's create-react-app. I've completed all the instructions to add SASS to my app, now I'm trying to add Bootstrap and customize the theme. I've been able to add bootstrap but the customizing of the variables is not working. Here is my setup:
package.json
"bootstrap": "^4.0.0-beta",
In my React layout container:
import 'bootstrap/dist/css/bootstrap.css';
import '../styles/custom_bootstrap.scss';
Bootstrap is working fine but the customizations/overrides are not having an effect.
custom_bootstrap.scss:
$theme-colors: (
primary: orange
) !default;
The primary is still blue. What am I doing wrong here?
Updated
MainLayout.jsx
import '../styles/index.css'
index.scss
#import 'custom_bootstrap';
#import 'bootstrap/scss/bootstrap';
If I remove #import 'custom_bootstrap'; bootstrap compiles successfully.
If I add it back and update the following:
_custom_bootstrap.scss
$theme-colors: (
primary: orange
) !default;
I'm getting compile errors like so:
09:44:56 web.1 | => changed: /Users/xxx/sites/xxx/client/src/styles/index.scss
09:44:56 web.1 | {
09:44:56 web.1 | "status": 1,
09:44:56 web.1 | "file": "/Users/xxx/sites/xxx/client/node_modules/bootstrap/scss/_forms.scss",
09:44:56 web.1 | "line": 280,
09:44:56 web.1 | "column": 21,
09:44:56 web.1 | "message": "argument `$color` of `rgba($color, $alpha)` must be a color\n\nBacktrace:\n\tnode_modules/bootstrap/scss/_forms.scss:280, in function `rgba`\n\tnode_modules/bootstrap/scss/_forms.scss:280",
09:44:56 web.1 | "formatted": "Error: argument `$color` of `rgba($color, $alpha)` must be a color\n\n Backtrace:\n \tnode_modules/bootstrap/scss/_forms.scss:280, in function `rgba`\n \tnode_modules/bootstrap/scss/_forms.scss:280\n on line 280 of node_modules/bootstrap/scss/_forms.scss\n>> background-color: rgba($form-feedback-invalid-color,.8);\n --------------------^\n"
09:44:56 web.1 | }
It looks like you're importing the compiled bootstrap CSS:
import 'bootstrap/dist/css/bootstrap.css';
Variables you set in your custom SCSS won't have any effect on this.
Import your variables, then bootstrap's SCSS. Omit the !default flag. Example:
styles/styles.scss
#import 'variables';
#import '[relative path to boostrap]/scss/bootstrap';
styles/_variables.scss
$theme-colors: (
primary: orange
);
You cannot change sass variables that are in the compiled .css bootstrap file. They are no longer sass variables at that point. You need to override them before they are compiled. So start by importing in bootstrap to your custom file and then override it. Then you can compile it all into one .css file.
import 'bootstrap/dist/css/bootstrap.scss';
$theme-colors: (
primary: orange
) !default;
Related
I'm trying to use the #cucumber/monaco editor library in a React project which uses tree-sitter for NodeParserAdapter but I'm getting a bunch of resolve errors in the tree-sitter when I do this. I'm importing the NodeParserAdapter, not the WasmParserAdapter from the cucumber/language-service as we aren't using WebAssembly in our project.
Environment: Node v16.17.1 (Docker Image 16.17)
Error Log:
[0]
[0] Search for the keywords to learn more about each warning.
[0] To ignore, add // eslint-disable-next-line to the line before.
[0]
[0] WARNING in ./node_modules/tree-sitter-c-sharp/bindings/node/index.js 2:2-77
[0] Module not found: Error: Can't resolve '../../build/Release/tree_sitter_c_sharp_binding' in '/usr/src/my_project/node_modules/tree-sitter-c-sharp/bindings/node'
[0]
[0] WARNING in ./node_modules/tree-sitter-c-sharp/bindings/node/index.js 9:4-77
[0] Module not found: Error: Can't resolve '../../build/Debug/tree_sitter_c_sharp_binding' in '/usr/src/my_project/node_modules/tree-sitter-c-sharp/bindings/node'
[0]
[0] WARNING in ./node_modules/tree-sitter-java/bindings/node/index.js 2:2-74
[0] Module not found: Error: Can't resolve '../../build/Release/tree_sitter_java_binding'
in '/usr/src/my_project/node_modules/tree-sitter-java/bindings/node'
[0]
[0] WARNING in ./node_modules/tree-sitter-java/bindings/node/index.js 9:4-74
[0] Module not found: Error: Can't resolve '../../build/Debug/tree_sitter_java_binding' in '/usr/src/my_project/node_modules/tree-sitter-java/bindings/node'
[0]
[0] WARNING in ./node_modules/tree-sitter-php/index.js 2:2-69
[0] Module not found: Error: Can't resolve './build/Release/tree_sitter_php_binding' in '/usr/src/my_project/node_modules/tree-sitter-php'
[0]
[0] WARNING in ./node_modules/tree-sitter-php/index.js 5:4-69
[0] Module not found: Error: Can't resolve './build/Debug/tree_sitter_php_binding' in '/usr/src/my_project/node_modules/tree-sitter-php'
[0]
[0] WARNING in ./node_modules/tree-sitter-python/bindings/node/index.js 2:2-76
[0] Module not found: Error: Can't resolve '../../build/Release/tree_sitter_python_binding' in '/usr/src/my_project/node_modules/tree-sitter-python/bindings/node'
[0]
[0] WARNING in ./node_modules/tree-sitter-python/bindings/node/index.js 9:4-76
[0] Module not found: Error: Can't resolve '../../build/Debug/tree_sitter_python_binding'
in '/usr/src/my_project/node_modules/tree-sitter-python/bindings/node'
[0]
[0] WARNING in ./node_modules/tree-sitter-ruby/bindings/node/index.js 2:2-74
[0] Module not found: Error: Can't resolve '../../build/Release/tree_sitter_ruby_binding'
in '/usr/src/my_project/node_modules/tree-sitter-ruby/bindings/node'
[0]
[0] WARNING in ./node_modules/tree-sitter-ruby/bindings/node/index.js 9:4-74
[0] Module not found: Error: Can't resolve '../../build/Debug/tree_sitter_ruby_binding' in '/usr/src/my_project/node_modules/tree-sitter-ruby/bindings/node'
[0]
[0] WARNING in ./node_modules/tree-sitter-typescript/bindings/node/index.js 2:2-80
[0] Module not found: Error: Can't resolve '../../build/Release/tree_sitter_typescript_binding' in '/usr/src/my_project/node_modules/tree-sitter-typescript/bindings/node'
[0]
[0] WARNING in ./node_modules/tree-sitter-typescript/bindings/node/index.js 9:4-80
[0] Module not found: Error: Can't resolve '../../build/Debug/tree_sitter_typescript_binding' in '/usr/src/my_project/node_modules/tree-sitter-typescript/bindings/node'
[0]
[0] WARNING in ./node_modules/tree-sitter/index.js 4:12-66
[0] Module not found: Error: Can't resolve './build/Release/tree_sitter_runtime_binding' in '/usr/src/my_project/node_modules/tree-sitter'
[0]
[0] WARNING in ./node_modules/tree-sitter/index.js 7:14-66
[0] Module not found: Error: Can't resolve './build/Debug/tree_sitter_runtime_binding' in
'/usr/src/my_project/node_modules/tree-sitter'
[0]
[0] webpack compiled with 14 warnings
Tree Sitter and the other tree-sitter-c-sharp, tree-sitter-java etc are all installed and in the node_modules directory of the project.
tree-sitter
tree-sitter-c-sharp
tree-sitter-cli
tree-sitter-java
tree-sitter-php
tree-sitter-python
tree-sitter-ruby
tree-sitter-typescript
And when I look in the tree-sitter/build/Release I can see the tree_sitter_runtime_binding.node file
root#abc123:/usr/src/my_project/node_modules/tree-sitter/build/Release# ls
obj.target tree_sitter.a tree_sitter_runtime_binding.node
So why can't tree-sitter resolve it?
Have tried Node 18, that didn't work, tried running the build command directly from the node_modules/tree-sitter directory, didn't work, have tried installing tree-sitter in a new folder on it's own and getting the same error. Any help much appreciated.
✅ What did you expect to see?
The tree-sitter package to resolve correctly and for the Monaco editor to work with the #cucumber/monaco library.
📦 Which tool/library version are you using?
+-- #cucumber/monaco#0.11.0
| +-- #cucumber/language-service#0.32.0
| | +-- #cucumber/cucumber-expressions#16.0.0
| | +-- #cucumber/gherkin-utils#8.0.0
| | +-- #cucumber/gherkin#24.0.0
| | +-- #cucumber/messages#19.1.4
| | +-- #types/js-search#1.4.0
| | +-- #types/mustache#4.2.1
| | +-- fuse.js#6.6.2
| | +-- js-search#2.0.0
| | +-- mustache#4.2.0
| | +-- tree-sitter-c-sharp#0.19.1
| | +-- tree-sitter-cli#0.20.6
| | +-- tree-sitter-java#0.19.1
| | +-- tree-sitter-php#0.19.0
| | +-- tree-sitter-python#0.20.1
| | +-- tree-sitter-ruby#0.19.0
| | +-- tree-sitter-typescript#0.20.1
| | +-- tree-sitter#0.20.0
| | +-- vscode-languageserver-types#3.17.2
| | `-- web-tree-sitter#0.20.5
| +-- monaco-editor#0.33.0
| `-- vscode-languageserver-types#3.17.2
Node.js 16.17.1, tried with later versions of Node but to no success.
React 18.2
🔬 How could we reproduce it?
Steps to reproduce the behavior:
Start a node:16.17 Docker container
Create a React project using the Create React App template
Install the Monaco editor library and #cucumber/monaco library
Create a TestEditor.jsx file
Import the NodeParserAdapter into the file
Bug should reproduce
Below is the code snippet I'm trying to run.
import React from 'react'
// Import the components
import VerticalNav from '../../components/navbar/VerticalNav'
import HorizontalNav from '../../components/navbar/HorizontalNav'
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'
import MonacoEditor from '#monaco-editor/react'
import { configureMonaco } from '#cucumber/monaco'
import { ParameterTypeRegistry } from '#cucumber/cucumber-expressions'
import {
buildSuggestions,
ExpressionBuilder,
jsSearchIndex,
} from '#cucumber/language-service'
import { NodeParserAdapter } from '#cucumber/language-service/node'
import { render } from 'react-dom'
const value = `#foo
Feature: Hello
Scenario: Hi
Given I have 58 cukes in my belly
And this is an undefined step
| some | poorly |
| formatted | table |
`
async function Editor() {
monaco.languages.register({ id: 'typescript' })
const sources = [
{
languageName: 'java',
uri: 'file:///tmp/StepDefinitions.java',
content: `class StepDefinitions {
#Given("I have {int} cukes in my belly" )
void method1() {
}
#Given("there are {int} blind mice")
void method2() {
}
#Given("there is/are some/none/1 apple(s)")
void method2() {
}
}
`,
},
]
const adapter = new NodeParserAdapter('.')
await adapter.init()
const expressionBuilder = new ExpressionBuilder(adapter)
const { expressionLinks } = expressionBuilder.build(sources, [])
const expressions = expressionLinks.map((link) => link.expression)
const registry = new ParameterTypeRegistry()
const docs = buildSuggestions(
registry,
[
'I have 42 cukes in my belly',
'I have 96 cukes in my belly',
'there are 38 blind mice',
],
expressions,
)
const index = jsSearchIndex(docs)
return configureMonaco(monaco, index, expressions)
}
export default function EditorElement() {
const options = {
value,
language: 'gherkin',
theme: 'vs-dark',
// semantic tokens provider is disabled by default
'semanticHighlighting.enabled': true,
}
Editor()
.then((configureEditor) => {
// #ts-ignore
console.log('Hello World')
render(
<MonacoEditor
height="90vh"
options={options}
className="editor"
configure={configureEditor}
/>,
document.getElementById('editor'),
)
})
.catch((err) => console.error(err.stack))
return (
<>
<div className="flex">
<VerticalNav />
<div className="h-screen flex-1">
<HorizontalNav />
<div className="pt-9 w-[90%] m-auto">
<div id="editor"></div>
</div>
</div>
</div>
</>
)
}
I tried following the example in the try folder, just replacing the WasmParserAdapter with the NodeParserAdapter but then I couldn't get any further with the resolve errors.
Not sure if this is a problem with the tree-sitter library or a React project configuration problem. Tried a few solutions online but nothing seems to work. Any advice or help is much appreciated
I'm using Jest in Vite. It works until I import a module from node_module.
import { defineComponent } from 'vue'
import { useCookies } from '#vueuse/integrations/useCookies'
I got this error.
FAIL src/components/MyComponent/index.test.ts
● Test suite failed to run
Cannot find module '#vueuse/integrations/useCookies' from 'src/components/MyComponent/index.vue'
Require stack:
src/components/MyComponent/index.vue
src/components/MyComponent/index.test.ts
16 | <script lang="ts">
17 | import { defineComponent } from 'vue'
> 18 | import { useCookies } from '#vueuse/integrations/useCookies'
| ^
19 |
20 | export default defineComponent({
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:306:11)
I guess somehow Jest cannot resolve the module starts with '#'. Maybe I should write a moduleNameMapper? I also tried to install vite-jest, but somehow my app just crash, maybe I mess up something.
Anyway, thanks for your time, and if you need more information like my jest.config.js or vite.config.ts, please let me know.
Thank you.
Use moduleNameMapper in your jest.config.js file like following:
module.exports = {
//...
moduleNameMapper: {
"^#/(.*)$": "<rootDir>/src/$1",
},
};
Also, if you are using TypeScript, you should add the following to your tsconfig.json file as well:
{
"compilerOptions": {
"paths": {
"#/*": ["./src"]
}
}
}
Running jest on the application fails with:
Details:
/home/**/node_modules/monaco-editor/esm/vs/editor/editor.api.js:5
import { EDITOR_DEFAULTS } from './common/config/editorOptions.js';
^
SyntaxError: Unexpected token {
> 1 | import * as monaco from "monaco-editor/esm/vs/editor/editor.api.js";
| ^
2 |
3 | /**
4 | * Get create function for the editor.
at ScriptTransformer._transformAndBuildScript (node_modules/#jest/transform/build/ScriptTransformer.js:537:17)
at ScriptTransformer.transform (node_modules/#jest/transform/build/ScriptTransformer.js:579:25)
at Object.<anonymous> (src/utils/editor-actions.js:1:1)
Application has installed packages for jest and babel-jest.
Babel config:
const presets = [
[
"#babel/env",
{
targets: {
edge: "17",
firefox: "60",
chrome: "67",
safari: "11.1"
},
useBuiltIns: "usage",
corejs: 3,
}
],
"#babel/preset-react"
];
const plugins = [
"#babel/plugin-proposal-object-rest-spread",
"#babel/plugin-proposal-class-properties",
"babel-plugin-styled-components"
];
module.exports = { presets, plugins };
The import statement as suggested in the docs for lazy loading modules from monaco leads to the esm folder, which jest is not familiar with.
import * as monaco from "monaco-editor/esm/vs/editor/editor.api.js";
By default, babel-jest would not transform node_modules and hence anything referencing the monaco-editor would error out. A possible solution is to include monaco-editor package into the compilation step by transformIgnorePatterns as mentioned in the docs
Add these to the jest config:
{
"transformIgnorePatterns": [
"node_modules\/(?!(monaco-editor)\/)"
]
}
PS: If you are using jest-dom, it might start complaining on not implmenting certain features from monaco-editor, you can mock it out with:
jest.mock("monaco-editor/esm/vs/editor/editor.api.js");
The only workaround that helped me in that issue (from here):
In folder __mocks__ create file react-monaco-editor.js with content:
import * as React from 'react';
export default function MonacoEditor() {
return <div />;
}
I have the same issue with Jest and Monaco and to make the tests pass I had to:
Add a moduleNameMapper for monaco-editor: #133 (comment)
Configure a setupTests.js like explained here: stackOverflow
I'm using:
"jest": "^24.9.0"
"babel-jest": "24.9",
"monaco-editor": "^0.20.0"
"react-monaco-editor": "0.33.0",
"monaco-editor-webpack-plugin": "^1.8.2",
I´m trying to dynamically import webpack in Node.js
if (condition) {
import('webpack').then(webpack => webpack);
}
However in my terminal I see the following error:
C:\Users\myUser\react\node_modules\#babel\core\lib\transformation\normalize-file.js:209
throw err;
^
SyntaxError: C:\Users\myUser\react\server\index.js: Support for the experimental syntax 'dynamicImport' isn't currently enabled (23:3):
19 |
20 | if (condition) {
> 21 | import('webpack').then(webpack => webpack);
| ^
22 |
Add #babel/plugin-syntax-dynamic-import (https://git.io/vb4Sv) to the 'plugins' section of your Babel config to enable parsing.
I have #babel/plugin-syntax-dynamic-import installed and in my .babelrc
{
"presets": ["#babel/preset-env", "#babel/preset-react"],
"plugins": [
"#babel/plugin-syntax-dynamic-import",
"#babel/plugin-proposal-class-properties"
]
}
I even tried to add it to the webpack conf file under the rule for .js with loader "babel-loader".
I´m trying to avoid CmJS
const webpack = require('webpack');
In any case I receive the same error and I cannot find a solution. Did anyone go through this? Thanks
add plugins: ["dynamic-import-webpack"] to .babelrc
and also install plug $npm i babel-plugin-dynamic-import-webpack --D
I'm using npm link to reference a typescript library I'm developing in my test project
Which means that my node_modules looks like this :
node_modules/
| myLib/
| | dist/
| | | subModule/
| | | | index.js
| | | | index.d.ts
| | | index.js
| | | index.d.ts
| | node_modules/
| | src/
| | tsconfig.json
| | package.json
Which implies that when I'm trying to reference my library using import X from "myLib" I have to tell the compiler that the sources are in the /dist forlder, not that the root of myLib.
I solved this by adding a "main": "./dist/index.js" in the package.json of myLib
The problem is when I try to import a path relative to myLib
Like import Y from "myLib/subModule"
This time it doesn't work.
Because instead of looking at node_modules/myLib/dist/subModule tsc is looking at node_modules/myLib/subModules/dist/ which doesn't exist.
How can I make the compiler to look at the right path for subModules ?
You can resolve this by using the "paths" key in the "compilerOptions" in your tsconfig.json. Something like this:
{
"compilerOptions": {
"paths": {
"myLib/*": "node_modules/myLib/dist/*"
}
}
}
Sadly, this is something of a standing issue with how the TypeScript compiler resolves definition files when you have a "types" key in your package.json.