Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

ipjs

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ipjs - npm Package Compare versions

Comparing version 5.1.0 to 5.1.1

2

package.json
{
"name": "ipjs",
"version": "5.1.0",
"version": "5.1.1",
"description": "Universal JavaScript build and packaging system",

@@ -5,0 +5,0 @@ "main": "src/build.js",

@@ -56,1 +56,43 @@ # Universal JavaScript Build and Packaging

### Avoid `instanceof`
The exports map means ESM and CJS environments load the same paths from different files:
```javascript
// package.json
{
"name": "my-esm-project",
"exports": {
"my-class": {
"import": "esm/src/my-class.js",
"require": "cjs/src/my-class.js",
}
}
// ...other fields
}
```
If a CJS file uses `instanceof` on an instance of a class loaded from and instantiated in an ESM file (or vice versa), the check will fail, even though there may only be one copy of that dependency in the tree - it's because they've been loaded from different files within that dependency.
For example, consider `my-esm-project`, built with ipjs and published as dual cjs/esm:
```javascript
// is-my-class.cjs
const MyClass = require('my-esm-project/my-class')
module.exports = (obj) => {
return obj instanceof MyClass
}
```
```javascript
// main.js
import isMyClass from './is-my-class.cjs'
import MyClass from 'my-esm-project/my-class'
const obj = new MyClass()
console.info(isMyClass(obj)) // false - perhaps not what we were expecting
```
It's possible to cross the ESM/CJS boundary like this several times during code execution, sometimes even within the same project so it's recommended not to use `instanceof`.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc