I am getting this error on npm run prod
npm run prod
> # prod /opt/atlassian/pipelines/agent/build
> encore production
Running webpack ...
ERROR Failed to compile with 2 errors4:15:08 PM
error in ./web/assets/src/scss/styles.scss
Module build failed:
$navbar-padding-horizontal: floor(math.div($grid-gutter-width, 2)) !default;
^
Invalid CSS after "... floor(math": expected expression (e.g. 1px, bold), was ".div($grid-gutter-w"
in /opt/atlassian/pipelines/agent/build/node_modules/bootstrap-sass/assets/stylesheets/bootstrap/_variables.scss (line 369, column 46)
# ./web/assets/src/scss/styles.scss 4:14-219
error in ./web/assets/src/scss/styles.scss
I've gone through quite a lot of fixes and one of them was to use sass instead of node-sass which I did but then it throws this errors
Error: Install node-sass to use enableSassLoader()
yarn add node-sass --dev
And if I disable .enableSassLoader() this this error occurs
FIX To load SASS files:
1. Add Encore.enableSassLoader() to your webpack.config.js file.
2. Install node-sass
yarn add node-sass --dev
This is my webpack.config.js
var Encore = require('#symfony/webpack-encore');
Encore
.setOutputPath('web/assets/public')
.setPublicPath('/assets/public')
.cleanupOutputBeforeBuild()
.enableBuildNotifications()
.addEntry('js/scripts','./web/assets/src/js/scripts.js')
.addEntry('js/video','./web/assets/src/js/video/video.js')
.addEntry('js/registration','./web/assets/src/js/registration/registration-lookup.js')
.addStyleEntry('styles', './web/assets/src/scss/styles.scss')
.enableSassLoader(function(sassOptions) {
}, {
resolveUrlLoader: false
})
.enablePostCssLoader()
.autoProvidejQuery()
.enableSourceMaps(!Encore.isProduction())
;
This is my devDependencies in package.json
"devDependencies": {
"#symfony/webpack-encore": "^0.17.1",
"autoprefixer": "^7.2.5",
"bootstrap-sass": "^3.3.7",
"cssnext": "^1.8.4",
"jquery": "^3.6.0",
"linting": "^1.0.0",
"node-sass": "^4.7.2",
"postcss-import": "^11.0.0",
"postcss-loader": "^2.0.10",
"sass-loader": "^6.0.6",
"webpack-notifier": "^1.5.1"
},
This is my styles.scss
#import "imports/_variables.scss";
$icon-font-path: "~bootstrap-sass/assets/fonts/bootstrap/";
#import "~bootstrap-sass/assets/stylesheets/bootstrap";
Looks like you are always using the latest bootstrap-sass but webpack encore doesn't support math.div.
If you remove the ^ in "^3.3.7" it will set the version to 3.3.7 which doesn't use the math.div function and instead uses "/" for division which should still work.
You should look at upgrading webpack encore but this may not be (easily) possible depending on the project.
Related
I have Git-pulled a symfony 5 project that works fine on the computer it was created, to pick it up on an new workstation. But when I launch my app, I get errors about the requested routes not existing. I also get an error when running "yarn encore dev".
Does anyone know what I missed ?
After git pulling, I've run :
symfony server:ca:install
composer install
yarn add --dev #symfony/webpack-encore
yarn add webpack-notifier --dev
yarn encore dev
The last command fails with that :
yarn encore dev
yarn run v1.22.19
$ C:\Users\Elyss\Documents\GitHub\NewFormadil\deux\Formadil\node_modules\.bin\encore dev
Running webpack ...
ERROR Failed to compile with 3 errors 15:10:13
Module build failed: Module not found:
"./assets/app.js" contains a reference to the file "bootstrap-star-rating".
This file can not be found, please check it for typos or update it if the file got moved.
"./assets/app.js" contains a reference to the file "bootstrap-star-rating/css/star-rating.css".
This file can not be found, please check it for typos or update it if the file got moved.
"./assets/app.js" contains a reference to the file "bootstrap-star-rating/themes/krajee-svg/theme.css".
This file can not be found, please check it for typos or update it if the file got moved.
Entrypoint app [big] 1.92 MiB = runtime.js 14.6 KiB vendors-node_modules_symfony_stimulus-bridge_dist_index_js-node_modules_bootstrap_dist_js_boo-43ff9a.js 1.88 MiB app.css 395 bytes app.js 21.8 KiB
webpack compiled with 3 errors
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
If I try and symfony:serve anyway, I get the following symfony error, although the route does exist and works fine on the original install :
RouteNotFoundException
RuntimeError
HTTP 500 Internal Server Error
An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "login" as such route does not exist.").
I've tried a "yarn upgrade", clearing caches and bunch of other ways to get everything up to date, but with no success.
Here is the webpack.config.js:
const Encore = require('#symfony/webpack-encore');
// Manually configure the runtime environment if not already configured yet by the "encore" command.
// It's useful when you use tools that rely on webpack.config.js file.
if (!Encore.isRuntimeEnvironmentConfigured()) {
Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev');
}
Encore
// directory where compiled assets will be stored
.setOutputPath('public/build/')
// public path used by the web server to access the output path
.setPublicPath('/build')
// only needed for CDN's or sub-directory deploy
//.setManifestKeyPrefix('build/')
/*
* ENTRY CONFIG
*
* Each entry will result in one JavaScript file (e.g. app.js)
* and one CSS file (e.g. app.css) if your JavaScript imports CSS.
*/
.addEntry('app', './assets/app.js')
// enables the Symfony UX Stimulus bridge (used in assets/bootstrap.js)
.enableStimulusBridge('./assets/controllers.json')
// When enabled, Webpack "splits" your files into smaller pieces for greater optimization.
.splitEntryChunks()
// will require an extra script tag for runtime.js
// but, you probably want this, unless you're building a single-page app
.enableSingleRuntimeChunk()
/*
* FEATURE CONFIG
*
* Enable & configure other features below. For a full
* list of features, see:
* https://symfony.com/doc/current/frontend.html#adding-more-features
*/
.cleanupOutputBeforeBuild()
.enableBuildNotifications()
.enableSourceMaps(!Encore.isProduction())
// enables hashed filenames (e.g. app.abc123.css)
.enableVersioning(Encore.isProduction())
.configureBabel((config) => {
config.plugins.push('#babel/plugin-proposal-class-properties');
})
// enables #babel/preset-env polyfills
.configureBabelPresetEnv((config) => {
config.useBuiltIns = 'usage';
config.corejs = 3;
})
// enables Sass/SCSS support
//.enableSassLoader()
// uncomment if you use TypeScript
//.enableTypeScriptLoader()
// uncomment if you use React
//.enableReactPreset()
// uncomment to get integrity="..." attributes on your script & link tags
// requires WebpackEncoreBundle 1.4 or higher
//.enableIntegrityHashes(Encore.isProduction())
// uncomment if you're having problems with a jQuery plugin
//.autoProvidejQuery()
;
module.exports = Encore.getWebpackConfig();
And the package.json:
{
"devDependencies": {
"#hotwired/stimulus": "^3.0.0",
"#popperjs/core": "^2.11.4",
"#symfony/stimulus-bridge": "^3.0.0",
"#symfony/webpack-encore": "^1.8.1",
"bootstrap": "^5.1.3",
"core-js": "^3.0.0",
"jquery": "^3.6.0",
"regenerator-runtime": "^0.13.2",
"webpack-notifier": "^1.15.0"
},
"license": "UNLICENSED",
"private": true,
"scripts": {
"dev-server": "encore dev-server",
"dev": "encore dev",
"watch": "encore dev --watch",
"build": "encore production --progress"
},
"dependencies": {
"#fortawesome/fontawesome-free": "^5.15.4",
"autoprefixer": "^10.4.2",
"chart.js": "^3.7.0",
"composer": "^4.1.0",
"postcss-loader": "^6.2.1",
"sass": "^1.48.0",
"sass-loader": "^12.4.0",
"scoop": "^0.0.2"
}
}
I am currently working on a website using symfony and i use webpack to compile the CSS and JS. When i try npm run watch, i get the following :
TypeError: The 'compilation' argument must be an instance of Compilation
at Function.getCompilationHooks (C:\Users\Louis\desktop\NEWPLANTE-2\node_modules\webpack\lib\NormalModule.js:227:10)
at C:\Users\Louis\desktop\NEWPLANTE-2\node_modules\#symfony\webpack-encore\lib\webpack-manifest-plugin\index.js:56:24
at _next46 (eval at create (C:\Users\Louis\Desktop\NEWPLANTE-2\node_modules\tapable\lib\HookCodeFactory.js:19:10), <anonymous>:50:1)
at _next24 (eval at create (C:\Users\Louis\Desktop\NEWPLANTE-2\node_modules\tapable\lib\HookCodeFactory.js:19:10), <anonymous>:97:1)
at _next2 (eval at create (C:\Users\Louis\Desktop\NEWPLANTE-2\node_modules\tapable\lib\HookCodeFactory.js:19:10), <anonymous>:144:1)
at Hook.eval [as call] (eval at create (C:\Users\Louis\Desktop\NEWPLANTE-2\node_modules\tapable\lib\HookCodeFactory.js:19:10), <anonymous>:152:1)
at Hook.CALL_DELEGATE [as _call] (C:\Users\Louis\Desktop\NEWPLANTE-2\node_modules\tapable\lib\Hook.js:14:14)
at Compiler.newCompilation (C:\Users\Louis\Desktop\NEWPLANTE-2\node_modules\webpack\lib\Compiler.js:1122:26)
at C:\Users\Louis\Desktop\NEWPLANTE-2\node_modules\webpack\lib\Compiler.js:1166:29
at Hook.eval [as callAsync] (eval at create (C:\Users\Louis\Desktop\NEWPLANTE-2\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:6:1)
I already checked, webpack is installed only once so there is no duplicate.
I tried several times deleting package.json, package-lock.json and node_modules and re running npm install But i still got the same error when running npm run watch.
Node and npm are already up to date so it should not be an update problem.
PS C:\Users\Louis\desktop\NEWPLANTE-2> npm -v
8.13.2
PS C:\Users\Louis\desktop\NEWPLANTE-2> node -v
v16.14.2
Here is the content of my package.json file
{
"devDependencies": {
"#hotwired/stimulus": "^3.0.0",
"#symfony/stimulus-bridge": "^3.0.0",
"#symfony/webpack-encore": "^1.8.1",
"core-js": "^3.0.0",
"regenerator-runtime": "^0.13.2",
"webpack-notifier": "^1.6.0"
},
"license": "UNLICENSED",
"private": true,
"scripts": {
"dev-server": "encore dev-server",
"dev": "encore dev",
"watch": "encore dev --watch",
"build": "encore production --progress"
}
}
Im not the only member in this project, i have checked with my teammates, the npm run watch is working for them. I am not sure why mine is not working although we have the same code and the same files.
Here is the content of webpack.config.js
const Encore = require("#symfony/webpack-encore");
// Manually configure the runtime environment if not already configured yet by the "encore" command.
// It's useful when you use tools that rely on webpack.config.js file.
if (!Encore.isRuntimeEnvironmentConfigured()) {
Encore.configureRuntimeEnvironment(process.env.NODE_ENV || "dev");
}
Encore
// directory where compiled assets will be stored
.setOutputPath("public/build/")
// public path used by the web server to access the output path
.setPublicPath("/build")
// only needed for CDN's or sub-directory deploy
//.setManifestKeyPrefix('build/')
/*
* ENTRY CONFIG
*
* Each entry will result in one JavaScript file (e.g. app.js)
* and one CSS file (e.g. app.css) if your JavaScript imports CSS.
*/
.addEntry("app", "./assets/app.js")
.addEntry("homepage", "./assets/homepage.js")
.addEntry("about", "./assets/about.js")
.addEntry("annonce", "./assets/annonce.js")
.addEntry("contact", "./assets/contact.js")
.addEntry("faq", "./assets/faq.js")
.addEntry("mentions", "./assets/mentions.js")
.addEntry("signup", "./assets/signup.js")
.addEntry("profil", "./assets/profil.js")
.addEntry("createAnnonce", "./assets/createAnnonce.js")
.addEntry("signup2", "./assets/signup2.js")
.addEntry("validation", "./assets/validation.js")
.addEntry("cgu", "./assets/cgu.js")
.addEntry("error404", "./assets/error404.js")
.addEntry("login", "./assets/login.js")
.addEntry("payment", "./assets/payment.js")
.addEntry("recap", "./assets/recap.js")
.addEntry("verify", "./assets/verify.js")
.addEntry("errors", "./assets/errors.js")
// .splitEntryChunks()
// enables the Symfony UX Stimulus bridge (used in assets/bootstrap.js)
.enableStimulusBridge("./assets/controllers.json")
// When enabled, Webpack "splits" your files into smaller pieces for greater optimization.
.splitEntryChunks()
// will require an extra script tag for runtime.js
// but, you probably want this, unless you're building a single-page app
.enableSingleRuntimeChunk()
/*
* FEATURE CONFIG
*
* Enable & configure other features below. For a full
* list of features, see:
* https://symfony.com/doc/current/frontend.html#adding-more-features
*/
.cleanupOutputBeforeBuild()
.enableBuildNotifications()
.enableSourceMaps(!Encore.isProduction())
// enables hashed filenames (e.g. app.abc123.css)
.enableVersioning(Encore.isProduction())
.configureBabel((config) => {
config.plugins.push("#babel/plugin-proposal-class-properties");
})
// enables #babel/preset-env polyfills
.configureBabelPresetEnv((config) => {
config.useBuiltIns = "usage";
config.corejs = 3;
});
// enables Sass/SCSS support
//.enableSassLoader()
// uncomment if you use TypeScript
//.enableTypeScriptLoader()
// uncomment if you use React
//.enableReactPreset()
// uncomment to get integrity="..." attributes on your script & link tags
// requires WebpackEncoreBundle 1.4 or higher
//.enableIntegrityHashes(Encore.isProduction())
// uncomment if you're having problems with a jQuery plugin
//.autoProvidejQuery()
module.exports = Encore.getWebpackConfig();
I started learning webpack. I am aware that webpack4 doesnt require a configuration explicitly. I created one for my project. On every build i see it picking up default config.
below is my package.json
{
"name": "feedback-clientlibs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "webpack"
},
"keywords": [],
"author": "hkesani",
"license": "ISC",
"devDependencies": {
"css-loader": "^3.5.3",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11"
},
"dependencies": {
"lodash": "^4.17.15"
}
}
and my webpack.config.js is as follows
var path = require('path');
module.export ={
entry : './js/feedback.js',
mode:'none',
output : {
filename:'feedback.js',
path:path.resolve(__dirname,'webpack.modules')
},
module:{
rules:[
{
test:/\.css$/,
use:['css-loader']
}
]
}
}
I have few css imports into the js files as below
import '../css/feedback.css'
import '../css/all.css'
whenever i run a build (i have cssloader installed) below is what i see
$ npm run build
> feedback-clientlibs#1.0.0 build C:\projects\br_translation\jcr\code\jcr_root\apps\r\dcloud\components\clientlibs\feedback-clientlibs
> webpack
Hash: 7c51d9af54f992c3e551
Version: webpack 4.43.0
Time: 106ms
Built at: 05/10/2020 10:39:42 PM
1 asset
Entrypoint main = main.js
[0] ./src/index.js 6.17 KiB {0} [built]
[1] ./css/feedback.css 302 bytes {0} [built] [failed] [1 error]
[2] ./css/all.css 292 bytes {0} [built] [failed] [1 error]
WARNING in configuration
The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each environment.
You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/configuration/mode/
ERROR in ./css/feedback.css 1:0
Module parse failed: Unexpected character '#' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> #feedback {
| height: 5em;
| padding: 10px 22px 8px 22px;
# ./src/index.js 1:0-28
ERROR in ./css/all.css 1:0
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> .ratings-stars {
| margin-bottom: 15px;
| height: 13px;
# ./src/index.js 2:0-23
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! feedback-clientlibs#1.0.0 build: `webpack`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the feedback-clientlibs#1.0.0 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\hkesani\AppData\Roaming\npm-cache\_logs\2020-05-10T17_09_42_363Z-debug.log
Any help is appreciated.
Thanks
Have you tried it with style-loader?
npm install --save-dev style-loader
And update your webpack.config.js rules to:
rules: [
{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
}
]
I also notice you did not supply a production flag for your webpack command I would update that script to run:
webpack --mode production -p
Then in your output path try a directory name without the period. This may or may not be the reason but it is normally a naming convention to use a dash or underscore for directory names.
path: path.resolve(__dirname,'webpack_modules')
I think it's defined [here]enter link description here.
It can also be inspected via node:
const webpack = require('webpack')
new webpack.WebpackOptionsDefaulter()
I have a master.scss with many imports from other .scss files. If I change a * .scss file master.css is generated automatically.
I use only the NPM, no Gulp or Grunt! This should remain so.
My current build script:
"scripts": {
"watch-sass": "sass --watch src/scss/master.scss:dist/css/master.css"
}
That's nice but takes a long time to compile!
Now I'm trying to use node-sass. It should compile very fast.
Unfortunately, I do not understand it completely ...
node-sass is installed, via npm install node-sass
Where do I use the following (from docs)?
var sass = require('node-sass');
sass.render({
file: scss_filename,
[, options..]
}, function(err, result) { /*...*/ });
// OR
var result = sass.renderSync({
data: scss_content
[, options..]
});
This is not so in the package.json, right?
Here's a tutorial, what I've read: Using NPM as a Task Runner
The script is good. How can I use it?
"scripts": {
"sass": "node-sass sass/ -o build/css/"
}
This will compile all of the sass files (that don't start with an underscore) to the build/css/ directory.
I hope for your help!
Maybe this covers your question:
How to compile or convert sass / scss to css with node-sass (no Ruby)?
If it's an option for you I would recommend using grunt, it will make things a lot simpler and faster. This grunt plugin is probably the best option: https://www.npmjs.com/package/grunt-contrib-sass
// UPDATE
I followed the tutorial you sent and it's very straightforward.
You create a file in your root folder called "package.json" containing the following:
{
"watches": {
"sass": "sass/**"
},
"scripts": {
"sass": "node-sass sass/ -o build/css/",
"dev": "rerun-script"
}
}
You then open the command line in the root folder and run the following:
npm install --save-dev node-sass
The above installs node-sass
You then run:
npm install --save-dev rerun-script
The above creates a watch task so you don't have to rerun node-sass everytime you make changes
And last you run
npm run dev
Done!
Documentation.
If you want automatically compile files then you need to put the flag -w
node-sass -w -r assets/src/scss/ -o assets/dist/css/
My package.json
{
"name": "my-project",
"version": "1.0.0",
"scripts": {
"build:js": "watchify assets/src/js/main_1.js -o 'exorcist assets/dist/js/main_1.js.map > assets/dist/js/main_1.js' -d -t [babelify --presets [latest]]",
"build:scss": "node-sass -w -r assets/src/scss/ -o assets/dist/css/",
"build": "npm run build:scss & npm run build:js"
},
"devDependencies": {
"babel-cli": "^6.0.0",
"babel-preset-latest": "^6.16.0",
"babelify": "^7.3.0",
"browserify": "^13.1.1",
"exorcist": "^0.4.0",
"node-sass": "^4.5.0",
"watchify": "^3.7.0"
},
"browserify": {
"transform": [
"babelify"
]
}
}
Actual version of package.json: https://gist.github.com/artamonovdev/5f24aaca504e4d1b299bba0413f0a57d
The watch mode in node-sass doesn't run the first compilation. It supposes that you have already ran node-sass.
Personally, I use something like this:
{
"scripts": {
"sass": "node-sass -o /path/to/dist /path/to/src",
"sass:watch": "npm run sass && npm run sass -- --watch --recursive"
}
}
And you can use it like this: npm run sass:watch
My goal is the be able to build my project to two separate build folders, each with its' own Grunt tasks.
I noticed the grunt-cli has the --gruntfile option which allows you to specify another Gruntfile to use. So far, I have a Gruntfile.js working perfectly (near stock from Yeoman). Also, I have another Gruntfile2.js sitting alongside.
Gruntfile.js
var yeomanConfig = {
app: 'app',
dist: '../www_browser'
};
Gruntfile2.js
var yeomanConfig = {
app: 'app',
dist: '../www'
};
grunt build is meant to run Gruntfile.js, and does so perfectly.
grunt build --gruntfile Gruntfile2.js is meant to run Gruntfile2.js, and does so with some hiccups. (supposed to build to ../www folder NOT ../www_browser folder)
The --gruntfile directive builds to the proper folder for almost every task except grunt-usemin and gunt-contrib-htmlmin. I know this because of this output to the console here:
Running "usemin:css" (usemin) task
Processing as CSS - ../www_browser/styles/22f60055.main.css
Running "concurrent:dist" (concurrent) task
Running "htmlmin:dist" (htmlmin) task
File ../www_browser/404.html created.
File ../www_browser/index.html created.
You'll notice the ../www_browser, here in console output. Every other task runs in the expected ../www folder.
Is this a usemin cache thing? Grunt cache thing? Or do some tasks simply run from the default Gruntfile.js regardless of the --gruntfile Gruntfile2.js directive?
I have given up on trying to do multiple targets from a single Gruntfile for now. There are too many dependencies in Yeoman's Gruntfile.js that don't yet support multiple build targets, and I spent 12 hours to no avail with that approach.
Version Info
$: grunt --version
grunt-cli v0.1.9
grunt v0.4.1
$: npm --version
1.2.25
$: yo --version
1.0.3
package.json
{
"name": "myapp",
"version": "0.0.0",
"dependencies": {},
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-copy": "~0.4.1",
"grunt-contrib-concat": "~0.1.3",
"grunt-contrib-coffee": "~0.6.5",
"grunt-contrib-uglify": "~0.2.0",
"grunt-contrib-compass": "~0.2.0",
"grunt-contrib-jshint": "~0.4.1",
"grunt-contrib-cssmin": "~0.6.0",
"grunt-contrib-connect": "~0.2.0",
"grunt-contrib-clean": "~0.4.0",
"grunt-contrib-htmlmin": "~0.1.3",
"grunt-bower-requirejs": "~0.4.1",
"grunt-contrib-requirejs": "~0.4.0",
"grunt-contrib-imagemin": "~0.1.3",
"grunt-contrib-watch": "~0.4.0",
"grunt-rev": "~0.1.0",
"grunt-usemin": "~0.1.10",
"grunt-mocha": "~0.3.0",
"grunt-open": "~0.2.0",
"grunt-svgmin": "~0.1.0",
"grunt-concurrent": "~0.1.0",
"matchdep": "~0.1.1",
"connect-livereload": "~0.2.0"
},
"engines": {
"node": ">=0.8.0"
}
}
It looks like you're using an older version of grunt-concurrent, which doesn't seem to be passing the grunt flags through to the child-processes.
See here: https://github.com/sindresorhus/grunt-concurrent/blob/v0.1.0/tasks/concurrent.js#L11
On the current version of the plugin, the flags are passed, see here: https://github.com/sindresorhus/grunt-concurrent/blob/v0.3.1/tasks/concurrent.js#L22
So, I suggest updating your version of grunt-concurrent:
npm install grunt-concurrent#latest --save-dev