Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I force node.js require to be case sensitive?

Since my Mac has a case-insensitive filesystem case related typos will not be caught when running tests locally, however they fail on the build server which is running Linux.

For example: require('./mymodule') will find ./myModule.js when running on Lion, but not on Linux.

Since I'd like to have the tests fail locally as well in order to not break the build on the server, I'm looking for a way to make node.js require more strict in that it throws an error if it the filename is not exact (i.e. has a difference in casing).

Does anyone know of a way to accomplish this?

EDIT:

Since there seemed no good solution for this problem out there I created valiquire.

This tool validates all requires found in an entire nodejs project also ensuring that the casing is correct.

like image 626
Thorsten Lorenz Avatar asked Nov 29 '12 02:11

Thorsten Lorenz


People also ask

Is Nodejs case-sensitive?

JavaScript is a case-sensitive language. This means that language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters.

Is require case-sensitive?

Require is not case insensitive on linux but is on windows · Issue #14019 · nodejs/node · GitHub.

Is NPM case-sensitive?

NPM packages are not allowed upper case characters in their name, seemingly because unix filesystems are case-sensitive, which creates "a recipe for confusion and nonportable software".

When should we not use Nodejs?

js receives a CPU bound task: Whenever a heavy request comes to the event loop, Node. js would set all the CPU available to process it first, and then answer other requests queued. That results in slow processing and overall delay in the event loop, which is why Node. js is not recommended for heavy computation.


1 Answers

If you use webpack, check out https://github.com/Urthen/case-sensitive-paths-webpack-plugin

Just installed it for our dev builds. Would have saved us from taking prod down multiple times... Which, if you're on this question, is already probably happening 😉

Install

npm install --save-dev case-sensitive-paths-webpack-plugin 

Usage

const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');  const webpackConfig = {     plugins: [         new CaseSensitivePathsPlugin(),         // other plugins ...     ],     // other webpack config ... }; 
like image 123
Andrew Rasmussen Avatar answered Sep 19 '22 11:09

Andrew Rasmussen