Hot reload not working properly for Tailwind on WSL2 - tailwind-css

o/
Just started a new personal project with Remix & TailwindCSS. Everything works fine with raw Remix install, but the css hot reload is broken when I add Tailwind. The first class added is applied, but not the next ones.
I think it must be related to WSL2 (Windows Subsystem for Linux), because it works fine on my linux laptop.
My config is exactly the one describe on Remix documentation.
Env
WSL2 with Ubuntu 20.04
node: v16.13.2 (also tried with v17.4.0)
npm: v8.4.0
app/root.tsx
...
import tailwindStylesUrl from "./tailwind.css";
export const links: LinksFunction = () => {
return [
{
rel: "stylesheet",
href: tailwindStylesUrl,
},
];
};
...
tailwind.config.js
module.exports = {
content: ["./app/**/*.{ts,tsx}"],
theme: {
extend: {},
},
plugins: [],
};
package.json
...
"scripts": {
"build": "npm run build:css && remix build",
"build:css": "tailwindcss -o ./app/tailwind.css",
"dev": "concurrently \"npm run dev:css\" \"remix dev\"",
"dev:css": "tailwindcss -o ./app/tailwind.css --watch",
"postinstall": "remix setup node",
"start": "remix-serve build"
},
"dependencies": {
"#remix-run/react": "^1.1.3",
"#remix-run/serve": "^1.1.3",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"remix": "^1.1.3"
},
"devDependencies": {
"#remix-run/dev": "^1.1.3",
"#types/react": "^17.0.24",
"#types/react-dom": "^17.0.9",
"concurrently": "^7.0.0",
"tailwindcss": "^3.0.17",
"typescript": "^4.1.2"
},
...
console
$ npm run dev
> dev
> concurrently "npm run dev:css" "remix dev"
[0]
[0] > dev:css
[0] > tailwindcss -o ./app/tailwind.css --watch
[0]
[1] (node:16121) ExperimentalWarning: stream/web is an experimental feature. This feature could change at any time
[1] (Use `node --trace-warnings ...` to show where the warning was created)
[1] (node:16121) ExperimentalWarning: buffer.Blob is an experimental feature. This feature could change at any time
[1] Watching Remix app in development mode...
[1] đź’ż Built in 258ms
[1] Remix App Server started at http://xxx.xx.xxx.xx:3000
[0]
[0] Rebuilding...
[0] Done in 117ms.
[1] đź’ż File changed: app/tailwind.css
[1] đź’ż Rebuilding...
[1] đź’ż Rebuilt in 48ms
[0]
[0] Rebuilding...
[0] Done in 14ms.
[1] đź’ż File changed: app/root.tsx
[1] đź’ż Rebuilding...
[1] đź’ż Rebuilt in 51ms
Thanks for your help 🙏

For those that come across this, a likely reason (although, according to the comments, it wasn't for this particular user) for hot reload functionality not working in WSL2 is that the project is stored on a Windows drive, rather than in the WSL2 ext4 filesystem.
Currently, inotify, the Linux API used by hot reload, is not supported in WSL2 on 9P filesystem drives (e.g. Windows drives mounted into WSL2).
There are usually at least three solutions:
Move the project files into the ext4 filesystem in WSL2, for instance, /etc/home/<username>/src or /etc/home/<username>/projects. inotify is supported on this filesystem.
Use WSL1 -- Most web development does not require the native Linux kernel features of WSL2 and works just as well (sometimes better) under WSL1. You can switch from WSL2 to WSL1 by running wsl --set-version <distroname> 1, although I recommend a backup (via wsl --export) first, just in case there are issues with the conversion.
As the OP was doing in this case, access the project through VSCode and the "Remote - WSL" extension. Since it started working again for the OP once they corrected a problem with the "WSL - Remote" extension, I'm still suspecting that inotify may have been the root cause.

U can try it add it to tailwind.config:
{
safelist: process.env !== 'production' ? [
{
pattern: /.*?/,
},
] : [],
}

Not ideal, but I found a way out.
If I use tailwind as a postcss plugin, the files are correctly hot reloaded. 🤷‍♀️
Edit: I think I found out what the problem was. I didn't notice that my VSCode wasn't running the WSL remote anymore. Since I reactivated it, everything works fine.

Related

#parcel/core: Failed to resolve 'process' from './node_modules/#firebase/firestore/dist/index.esm2017.js'

I'm working on a project and when I try to run parcel dev or build command it outputs the following error:
Ă— Build failed.
#parcel/core: Failed to resolve 'process' from './node_modules/#firebase/firestore/dist/index.esm2017.js'
D:\Workspace\Front-End\Apps\RISC-Aswan\node_modules\#firebase\firestore\dist\index.esm2017.js:5741:38
5740 | return t.store(e);
> 5741 | }
> | ^
5742 | // visible for testing
5743 | /** Parse User Agent to determine iOS version. Returns -1 if not found. */
It was working before and now I don't know the cause of the problem. I tried to delete node__modules folder and run npm install but nothing changes.
I have the following imports in the script file:
import { initializeApp } from 'firebase/app';
import { getFirestore, collection, addDoc } from 'firebase/firestore';
the second line importing the firestore is what causing the problem, commenting it leads to everthing works fine.
Here's a photo with the terminal message and the esm2017.js file
My package.json dependecies:
"devDependencies": {
"autoprefixer": "^10.4.2",
"parcel": "^2.2.1",
"postcss": "^8.4.6",
"tailwindcss": "^3.0.18"
},
"dependencies": {
"firebase": "^9.6.6",
"vanilla-hamburger": "^0.2.3"
}
for some reason modifying alias to the following worked in dev and build
"alias": {
"process": {
"global": "{}"
}
}
Here's the other suggested workaround i tried mentioned in this issue
used alias in my package.json file
"alias": {
"process": "false"
}
manually installed process package
"dependencies": {
"process": "^0.11.10",
},
updated node to v16.14.0 instead of v16.13.1.
used parcel build ./src/index.html and removed "source": "./src/index.html" in the package.json
In your package.json you are defining parcel to be the higher version compatible with 2.2.1:
"devDependencies": {
"autoprefixer": "^10.4.2",
"parcel": "^2.2.1"
// Rest of packages
Currently there is an issue in the GitHub repository for parcel regarding this problem with Firebase. While that issue shows your exact error message, the general issue to keep track of is this open issue, since this problem affects libraries other than Firebase. Something you could do is to avoid using an affected version of parcel (2.3.1 as far as I see on the issues), or keep track of the issue to update to a fixed version when it releases.
EDIT (2/23/2021):
It seems that both GitHub issues are now closed with the release of Parcel 2.3.2. I tested building a React project with Parcel and Firebase using version 2.3.1, and I encountered the exact same error as you. Updating to 2.3.2 solved the issue completely on my end without any other change of dependencies. Just in case anyone comes across this thread later on.
I was using yarn on netlify and had to do this to fix:
echo 'nodeLinker: node-modules' >> /opt/build/repo/.yarnrc.yml

When updating Next.js v10.1.13 to webpack5, getting warnings Can't resolve 'fsevents' in chokidar

npm install next react react-dom And running Node.js v12
Created most simple pages/index.tsx
export default function PageHome(props) {
return <>Hello World!</>
}
(I also had TypeScript configured as per Next.js instructions but not sure if that's making a difference.)
C:\GitHub\reproduce-nextjs-webpack5-error>npm run dev
...
event - compiled successfully
<w> [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Can't resolve 'fsevents' in 'C:\GitHub\reproduce-nextjs-webpack5-error\node_modules\next\node_modules\chokidar'
<w> while resolving 'fsevents' in C:\GitHub\reproduce-nextjs-webpack5-error\node_modules\next\node_modules\chokidar to a directory
<w> [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Can't resolve 'fsevents' in 'C:\GitHub\reproduce-nextjs-webpack5-error\node_modules\next\node_modules\chokidar'
<w> while resolving 'fsevents' in C:\GitHub\reproduce-nextjs-webpack5-error\node_modules\next\node_modules\chokidar to a directory
Self-answered solution below for future readers.
Upgrade Node.js
Delete package-lock.json and node_modules
Run npm install again
It works
Apparently something doesn't install when you run with an older Node.js version.
My package.json looked like
{
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "^10.1.3",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"devDependencies": {
"#types/react": "^17.0.3",
"typescript": "^4.2.4"
}
}
The same package.json will install slightly differently switching from Node.js v12 to Node.js v15 as I just observed. This is why you have to complete not just step 1, but also steps 2 & 3.
Before:
C:\GitHub\reproduce-nextjs-webpack5-error>node --version
v12.4.0
C:\GitHub\reproduce-nextjs-webpack5-error>npm run dev
> # dev C:\GitHub\reproduce-nextjs-webpack5-error
> next dev
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
info - Using webpack 5. Reason: future.webpack5 option enabled https://nextjs.org/docs/messages/webpack5
event - compiled successfully
<w> [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Can't resolve 'fsevents' in 'C:\GitHub\reproduce-nextjs-webpack5-error\node_modules\next\node_modules\chokidar'
<w> while resolving 'fsevents' in C:\GitHub\reproduce-nextjs-webpack5-error\node_modules\next\node_modules\chokidar to a directory
After:
C:\GitHub\reproduce-nextjs-webpack5-error>node --version
v15.14.0
C:\GitHub\reproduce-nextjs-webpack5-error>npm run dev
> dev
> next dev
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
info - Using webpack 5. Reason: future.webpack5 option enabled https://nextjs.org/docs/messages/webpack5
event - compiled successfully
event - build page: /
wait - compiling...
event - compiled successfully
Yay! No warnings!
While there are comments below about future changes in nextjs#canary, the above examples worked for me with versions listed.
Delete the .next folder and re-run npm run dev.
This happens when your system shuts down unexpectedly without saving.
I have resolved this problem by killing all node processes on my production server.

VS 2019 gruntfile.js no tasks found when using 'sass = require('node-sass')'

I'm trying to set up grunt-sass for the first time on a new .Net Core 3.1 web app. I've gone through MSFT's steps to add grunt to a project here outlined here and then modified it with the steps from the grunt-sass instructions here.
This however causes task runner explorer to state there are no tasks found.
Here is my package.json:
{
"name": "chapelstudios_www",
"version": "0.0.2",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://me#bitbucket.org/me/chapelstudios_www.git"
},
"author": "mr",
"license": "ISC",
"homepage": "https://bitbucket.org/me/chapelstudios_www#readme",
"private": true,
"devDependencies": {
"grunt": "^1.0.4",
"grunt-cli": "^1.3.2",
"grunt-sass": "^3.1.0",
"node-sass": "^4.13.1"
},
"dependencies": {
"gulp": "^4.0.2"
}
}
And this is my gruntfile.js:
const sass = require('node-sass');
require('load-grunt-tasks')(grunt);
module.exports = function (grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// Sass
sass: {
options: {
implementation: sass,
sourceMap: true, // Create source map
outputStyle: 'compressed' // Minify output
},
dist: {
files: [
{
expand: true, // Recursive
cwd: "Styles", // The startup directory
src: ["**/*.scss"], // Source files
dest: "wwwroot/css", // Destination
ext: ".css" // File extension
}
]
}
}
});
// Load the plugin
grunt.loadNpmTasks('grunt-sass');
// Default task(s).
grunt.registerTask('default', ['sass']);
};
I'm not sure how to get any more detailed error info then that but have tracked down the issue to the
const sass = require('node-sass');
line that is required by the grunt-sass instructions. If I change it to the string 'sass' that is recommended by older tutorials the task shows but fails when I attempt to actually run it.
I've also ran the following installations from an elevated powershell window in the project directory in an attempt to make sure they were installed into the project locally as I hear that to be a main issue:
npm install
npm install grunt
npm install grunt-cli
npm install --save-dev node-sass grunt-sass
At this point I'm out of ideas but I'm a newb so I'm sure I'm missing something obvious.
For anyone else visiting this with an existing project, I was having this issue with a pre-existing node-sass / grunt file on a new computer, and I found that bumping up the version of node-sass in my package.json caused VS to reinstall the packages and update the bindings as noted in the other answer.
I have a slight suspicion that there's a difference in versions between running grunt in my command prompt and whatever VS uses, since my grunt file worked just fine if I ran it manually, but would not show up in Task Runner Explorer.
Reviving an old topic but here is what worked for me. YMMV.
In Visual Studio, go to: Tools -> Options -> Web Package Management
-> External Web Tools.
Move $(PATH) above $(VSInstalledExternalTools).
I have no idea if there are any side effects to doing this.
credit to: https://developercommunity.visualstudio.com/solutions/314606/view.html
I found the following error which led me to do a rebuild:
Error: Missing binding A:\Projects\Repos\chapelstudios_www\node_modules\node-sass\vendor\win32-x64-79\binding.node
Node Sass could not find a binding for your current environment: Windows 64-bit with Node.js 13.x
Found bindings for the following environments:
- Windows 64-bit with Node.js 10.x
This usually happens because your environment has changed since running `npm install`.
Run `npm rebuild node-sass` to download the binding for your current environment.
As Jake mentioned I tracked the error down to this line as well:
const sass = require('node-sass');
Running rebuild didn't work. I found that after upgrading node from version 10.x to current version (12.18 Windows) and then rebuilding fixed the issue.
npm rebuild node-sass

I am currently trying to deploy to pm2-meteor with an error

pm2-meteor node, npm, pm2 missing error...
Hello, I am currently trying to deploy to pm2-meteor with an error.
The current situation is that I want to modify product that was developed by previous developer as meteor using mac.
I use Windows.
Although not particularly relevant, the first error that occurred was the package-lock.json error of product, which was significantly changed when meteor npm install. So I just got node modules for npm install.
Then I tried to modify the code and deploy it using the pm2-meteor.
An error occurs.
Building your app and deployment to host machine \
Missing node
Missing npm
Missing pm2
Since previous developers used nvm, I also installed nvm and now my nvm folder is configured as shown in the figure.
`
> { "appName": ",
>"appLocation": {"local": "../" },
>"meteoSettingsLocation": ",
>"meteoSettingsInRepo": false, "prebuildScript": ",
> MeteorBuildFlags: "--architecture os.linux.x86_64",
> "Env": {
> "ROOT_URL": ",
> "PORT": "3000",
> "MONGO_URL": "" }, "server": {
> "host": ",
> "username": "root",
> "deploymentDir": ",
> "loadProfile": ",
> "nvm": {
> "bin": "~/.nvm/nvm.sh",
> "use": "8.8.1"
> },
> "exec_mode": "cluster_mode",
> "instances": "0",
> "password": "" }, "allowUndeployment": true }
`
Above is a .json file. I deleted personal information.
However, I use nvm-windows because nvm does not support Windows.
This is a list I've tried so far.
Reinstall the mateor
Delete existing node.js and reinstall nvm
Reinstall pm2 and pm2-meteor
Reconfigure the json file using the command in pm2-meteor (init)
Rewrite the nvm path of the json file(above json file) to the location of the nvm on my computer
a part of my doubt
The discrepancy between nvm used by the former developer in mac and nvm-windows used in windows
Currently, pm2-meteor and pm2 are properly stored in the v8.8x folder in the nvm folder.
Please give me a good direction.

Error: Cannot find module “mongodb” after meteor upgrade to 1.6.1.1

edit - There is something strange: mongo appears in both package.json and in .meteor/packages files (should it appear in package.json at all?? it wasn't there before the update) but in different versions. here is my package.json:
{
"name": "something",
"version": "1.1.1",
"private": true,
"scripts": {
"start": "meteor run"
},
"dependencies": {
"#babel/runtime": "^7.0.0-beta.49",
"babel-runtime": "^6.26.0",
"bootstrap": "^3.3.7",
"google-protobuf": "^3.5.0",
"grpc": "^1.12.2",
"grpc-tools": "^1.6.6",
"meteor-node-stubs": "^0.3.3",
**"mongodb": "^3.1.0-beta4",**
"react": "^16.4.0",
"react-dom": "^16.4.0",
"react-progressbar.js": "^0.2.0",
"react-router": "^3.2.1",
"react-router-dom": "^4.2.2"
}
}
and here is my .meteor/packages:
meteor-base#1.3.0 # Packages every Meteor app needs to have
mobile-experience#1.0.5 # Packages for a great mobile UX
**mongo#1.4.2 # The database Meteor supports right now**
blaze-html-templates#1.0.4 # Compile .html files into Meteor Blaze views
reactive-var#1.0.11 # Reactive variable for tracker
tracker#1.1.3 # Meteor's client-side reactive programming library
standard-minifier-css#1.4.0 # CSS minifier run for production mode
standard-minifier-js#2.3.1 # JS minifier run for production mode
es5-shim#4.7.0 # ECMAScript 5 compatibility for older browsers
ecmascript#0.10.6 # Enable ECMAScript2015+ syntax in app code
shell-server#0.3.1 # Server-side component of the `meteor shell` command
session#1.1.7
tarang:ssl
After updating to 1.6.1.1, my app won’t run, crashing with message 'Error: Cannot find module “mongodb” '.
Tried to run meteor npm install, even took away the entire node_modules folder and built it again.
Tried to run meteor npm update.
Tried to run meteor npm install mongodb.
Tried to downgrade back to version 1.6.0.1.
Still can’t find mongodb.
Important - mongodb is there, all collections are there - I can access it through the terminal with "meteor mongo".
Any help?
If it helps - The data in the db can be erased if there is no other way.
(running on ubuntu 16.04)
Thanks
In the end, the problem was not in the project but in meteor globally, so I uninstalled and re-installed meteor globally, and everything got back to normal…
Thank you all!

Resources