sass-loader require("node-sass")); but I installed sass - sass

Im on a M1 apple, so node-sass wont work for me. Every site I work on, I uninstall node-sass and install sass( also change nvm use 16.2.0 if anyone has that issue).
this has always worked, but today after doing so I get the following errors
Module build failed (from ./node_modules/sass-loader/lib/loader.js):
Error: Cannot find module 'node-sass'
So I went into node_modules/sass-loader/lib/loader.js and found this on line 46
const render = getRenderFuncFromSassImpl(options.implementation || require("node-sass"));
and changed it to
const render = getRenderFuncFromSassImpl(options.implementation || require("sass"));
Everything works, css is compiled.. but what I did seems like a hack,
Is there a better way to do it?
Will this break things in future?
Why didn't it update automatically like the other 20 sites I work on?

You can set the implementation of sass-loader in your package.json so it will use value of options.implementation instead of require("node-sass"):
module.exports = {
module: {
rules: [
{
test: /\.s[ac]ss$/i,
use: [
"style-loader",
"css-loader",
{
loader: "sass-loader",
options: {
// Prefer `dart-sass`
implementation: require("sass"),
},
},
],
},
],
},
};
As for your third question, the doc states that:
By default the loader resolve the implementation based on your dependencies. Just add required implementation to package.json (sass or node-sass package) and install dependencies.
Maybe you still have node-sass listed as a dependency?

I struggled with the same problem. What ended up working was to delete package-lock.json and install everything again.

Related

When you use this plugin you must install `typescript`. error

I am using yarn 2 and react with webpack.
In my package is "typescript": ... defined. Once I start yarn start I am getting an error:
yarn workspace test start
When you use this plugin you must install `typescript`.
What is wrong? How should I fix it? Or debug it?
I've faced the similar issue when I was upgrading webpack from 4 to 5.
The problem was the version of react-dev-utils
Upgrading react-dev-utils from v10 to v12 made the issue disappear.
devDependencies {
...
"react-dev-utils": "^12.0.1",
...
}
You can be checked the value of your plugins config about ForkTsCheckerWebpackPlugin which the param key named tsconfig.
Error Message
Check [key, value] about ForkTsCheckerWebpackPlugin.
Find it in your node_modules, and set debug point, run the debugger.
You need to take a look at your webpack.config.js where ForkTsCheckerWebpackPlugin is initialized. ForkTsCheckerWebpackPlugin needs to be able to find the tsconfig file.
new ForkTsCheckerWebpackPlugin({
typescript: resolve.sync('typescript', {
basedir: paths.appNodeModules,
tsconfig: paths.appTsConfig,
})
}),
In my case I'm defining paths.appNodeModules and paths.appsTsConfig in a file called paths.js.
module.exports = {
appTsConfig: resolveApp('tsconfig.json'),
appNodeModules: resolveApp('node_modules'),
};

storybook: use awesome-typescript-loader

By default Storybook uses babel-loader, but the current version of babel-loader is incompatible to the one Storybook requires. So I decided to use awesome-typescript-loader instead. That is, my project uses babel-loader and Storybook uses awesome-typescript-loader.
I added the webpack.config.js file:
module.exports = ({ config }) => {
config.module.rules.push({
test: /\.(ts|tsx)$/,
use: [
{
loader: require.resolve('awesome-typescript-loader'),
},
],
});
config.resolve.extensions.push('.ts', '.tsx');
return config;
};
but Storybook still insist to load babel-loader.
ERR! Error: Cannot find module 'babel-loader'
How can I set up an alternative loader?
Try with #next version, there was a fix 5 days ago that solves it by skipping babel loader check.
This is how to run the init command with the #next version:
npx -p #storybook/cli#next sb init
Additionally, if you haven't already, clean up babel-loader from package.json, remove npm lock file, and re-run npm install.
Be aware #next is not the stable version, and this is not completely ideal, but if you are interested keep following the conversation

Missing Module When Building JavaScript

I'm building an internal tool in Laravel and I need a datetime picker for part of the interface. My research has suggested that Tempus Dominus is the solution most people use to solve this.
I've installed Tempus Dominus and Moment (through Node) and added them both to my app.js file. However when I try to compile the JS I get the following warning:
WARNING in ./node_modules/moment/min/moment.min.js
Module not found: Error: Can't resolve './locale' in 'C:\inetpub\wwwroot\salesdb\node_modules\moment\min'
# ./node_modules/moment/min/moment.min.js
# ./resources/js/app.js
# multi ./resources/js/app.js ./resources/sass/app.scss
This is how I'm importing them in the app.js file:
require('moment/min/moment.min.js');
require( 'tempusdominus-bootstrap-4/build/js/tempusdominus-bootstrap-4.js');
What am I missing?
The official Tempus Dominus Bootstrap plugin is unmaintained and is kinda buggy when it comes to ES6 and module bundlers.
I strongly advise you to install these two forks instead:
https://www.npmjs.com/package/tempusdominus
https://www.npmjs.com/package/tempusdominus-bootstrap
npm i tempusdominus tempusdominus-bootstrap
If you wanna make it work, you should inject/provide moment and jquery imports in the final build of your application (1st option), or make them globally available (2nd option).
1st option
What is your module bundler?
E.g., if you are using Rollup, you can configure the build like this using the Rollup's #rollup/plugin-inject plugin:
// Your imported plugins...
import inject from "#rollup/plugin-inject";
export default {
input: "src/index.js",
output: [
// You outputs...
],
plugins: [
inject({
$: "jquery",
jQuery: "jquery",
moment: "moment",
exclude: "src/**",
}),
// Your other Rollup plugins here...
],
};
For Webpack, you'd need to use the ProvidePlugin:
const webpack = require('webpack');
module.exports = {
entry: './index.js',
output: {
filename: '[name].js'
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
moment: 'moment'
})
]
};
2nd option
The other option would be to make moment and jQuery globally available in your app by adding the following lines to your index.js main entry point file:
import moment from "moment";
import $ from "jquery";
window.$ = window.jQuery = $;
window.moment = moment;
// Your other imports (tempusdominus-bootstrap as well) go here...
Though I didn't test, both options should work (let me know if not).
Of course, the preferred one would be to use a module bundler (1st option) and not to expose jQuery and/or moment to window.
And if you are using React, I advise you to use this library here instead (demo here). But that's another story.

Add angular-material to mean.io app

I'm trying to add angular-material to a mean.io application.
I have, in my custom package, used bower to install angular-material and now I have a .../public/assets/lib/angular-material folder.
So far so good. Now I want to use it in my custom mean.io module and according to their documentation I have added
MyPackage.angularDependencies(['ngMaterial']);
in my app.js file.
I have also aggregated angular-material.css and angular-material.js (not sure if this should be needed).
But, I get the following error:
Failed to instantiate module mean due to:
Error: [$injector:modulerr] http://errors.angularjs.org/1.4.8/$injector/modulerr?p0=m...)
at Error (native)
at http://127.0.0.1:3001/bower_components/angular/angular.min.js?v=90fb950dbc3e9296755d9cc23a211744:6:416
at http://127.0.0.1:3001/bower_components/angular/angular.min.js?v=90fb950dbc3e9296755d9cc23a211744:38:391
at n (http://127.0.0.1:3001/bower_components/angular/angular.min.js?v=90fb950dbc3e9296755d9cc23a211744:7:333)
at g (http://127.0.0.1:3001/bower_components/angular/angular.min.js?v=90fb950dbc3e9296755d9cc23a211744:37:488)
at http://127.0.0.1:3001/bower_components/angular/angular.min.js?v=90fb950dbc3e9296755d9cc23a211744:38:134
at n (http://127.0.0.1:3001/bower_components/angular/angular.min.js?v=90fb950dbc3e9296755d9cc23a211744:7:333)
at g (http://127.0.0.1:3001/bower_components/angular/angular.min.js?v=90fb950dbc3e9296755d9cc23a211744:37:488)
at eb (http://127.0.0.1:3001/bower_components/angular/angular.min.js?v=90fb950dbc3e9296755d9cc23a211744:41:249)
at c (http://127.0.0.1:3001/bower_components/angular/angular.min.js?v=90fb950dbc3e9296755d9cc23a211744:19:463
I'm assuming mean doesn't find the angular-material module and I need to specify its path somewhere. But I can't figure out where.
I had the same problem, this is happening because angular couldn't resolve some required libraries by material, I didn't get so deep into this investigation but I found an alternative solution as described below:
Navigate to the project root directory and then install angular material using bower:
$ bower install angular-material --save
Then, into the project root directory you will find the /config/assets.json file where AngularJS is included, now you add the angular material libraries like this:
{
"core": {
"css": {
"bower_components/build/css/dist.min.css": [
"bower_components/angular/angular-csp.css",
-> "bower_components/angular-material/angular-material.css",
"bower_components/angular-ui-select/dist/select.min.css"
]
},
"js": {
"bower_components/build/js/dist.min.js": [
"bower_components/jquery/dist/jquery.min.js",
"bower_components/angular/angular.min.js",
-> "bower_components/angular-aria/angular-aria.js",
-> "bower_components/angular-animate/angular-animate.js",
-> "bower_components/angular-material/angular-material.js",
"bower_components/angular-mocks/angular-mocks.js",
"bower_components/angular-cookies/angular-cookies.min.js",
"bower_components/angular-resource/angular-resource.min.js",
"bower_components/angular-sanitize/angular-sanitize.min.js",
"bower_components/angular-ui-router/release/angular-ui-router.min.js",
"bower_components/angular-jwt/dist/angular-jwt.min.js",
"bower_components/angular-bootstrap/ui-bootstrap-tpls.js",
"bower_components/angular-ui-select/dist/select.min.js",
"bower_components/web-bootstrap/index.js"
]
}
}
}
I know mean.io says to not alter the core packages, but I didin't find another way to make it work, if anybody has a better solution, please tell us.

Using node-normalize-scss with Grunt and Compass

I would like to use normalize.scss with my project that's currently set up with Grunt to compile the SCSS using Compass.
I've found this, and have installed it using the command below (from here: https://www.npmjs.com/package/node-normalize-scss)
npm install node-normalize-scss --save-dev
Underneath that are config examples for gulp and grunt, but not for compass. I have tried using:
includePaths: require('node-normalize-scss').includePaths
And adding that to my Compass options in my GruntFile.js, but I get an error that starts a little like this:
Running "compass:dev" (compass) task
Error: invalid option: --include-paths=/Applications/MAMP/htdocs/homepagev2/node_modules/node-normalize-scss
Usage: compass compile [path/to/project] [path/to/project/src/file.sass ...] [options]
Description:
compile project at the path specified or the current directory if not specified.
After that I read that I can use a simple command to import that path so that in my .scss I can #import "normalize"
importPath: 'node_modules/node-normalize-scss/',
But using this I get an error saying
>> File "styles/sass/style.scss" changed.
Local Npm module "node-normalize-scss" not found. Is it installed?
But it appears to be compilling normalize.scss into css, so I'm guessing it's kind of working.
Is there a better solution so I don't get the error on compile?
Thank you.
I, too, had this problem, and eventually found the answer on here: https://github.com/gruntjs/grunt-contrib-compass
The option to use for compass (which takes completely different options to sass) is importPath, which you've found, and it works the same way.
So, importPath: require('node-normalize-scss').includePaths should, hopefully, work for you.
This is my current Gruntfile.js in full:
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
compass: {
dist: {
options: {
importPath: require('node-normalize-scss').includePaths,
sassDir: 'path/to/sass',
cssDir: 'path/to/css'
}
}
},
watch: {
css: {
files: '**/*.scss',
tasks: ['compass']
}
}
});
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default',['watch']);
}

Resources