
Product
Introducing Custom Tabs for Org Alerts
Create and share saved alert views with custom tabs on the org alerts page, making it easier for teams to return to consistent, named filter sets.
strict-import
Advanced tools
Prevent
requirefrom searching upwards for required modules
The require() algorithm works by searching for a node_modules directory with your required module from the current directory and upwards until it reaches the system root directory.
This means that if you have nested projects, and have a module called foo installed at the top-level, the sub-projects can also import foo without installing it. While useful in some cases, it can also cause problems.
I made this module because I'm working on an Electron app, where we use electron-builder with a two package structure. We depended on module foo in the renderer, which was defined top-level, since we use Webpack for bundling. We later started using foo in the main process code too, which is placed in an app subdirectory. The problem is that we forgot to add foo as a dependency in the app directory, but it worked fine in development as require just found it at the top-level. In production, however, it crashed, since we no longer had the top-level dependency, as only the app directory is included in the built app. With this module, we can ensure that doesn't happen again.
$ npm install strict-import
At the top of your index.js file.
require('strict-import')(module);
// This now only works if `foo` is in `./node_modules`,
// but not if it's in `../node_modules`
const foo = require('foo');
MIT © Sindre Sorhus
FAQs
Prevent `require` from searching upwards for required modules
We found that strict-import demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Create and share saved alert views with custom tabs on the org alerts page, making it easier for teams to return to consistent, named filter sets.

Product
Socket’s Rust and Cargo support is now generally available, providing dependency analysis and supply chain visibility for Rust projects.

Security News
Chrome 144 introduces the Temporal API, a modern approach to date and time handling designed to fix long-standing issues with JavaScript’s Date object.