Skip to content

[Bug] setup-jest not exported in package.json, causing ERR_PACKAGE_PATH_NOT_EXPORTED on Node.js 22 #4094

@davor-bauk-sh

Description

@davor-bauk-sh

Environment

  • Dev OS: macOS Darwin 24.6.0
  • Node.js version: 22.17.0
  • npm version: 11.4.2
  • @rnmapbox/maps version: 10.2.7
  • React Native version: 0.81.5
  • React Native Architecture: Old Architecture (Paper/bridge)
  • Expo version: ~54.0.25
  • jest-expo version: 54.0.13

Issue Description

The recommended Jest setup from the Testing with Jest
documentation
fails with
ERR_PACKAGE_PATH_NOT_EXPORTED error on Node.js 22.

Root Cause: The package.json exports field does not include "./setup-jest", preventing the
recommended import path from resolving.

Error Message

Validation Error:

Module @rnmapbox/maps/setup-jest in the setupFilesAfterEnv option was not found.
        is: /path/to/project

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './setup-jest' is not defined by "exports" in

/path/to/project/node_modules/@rnmapbox/maps/package.json

Steps to Reproduce

  1. Install @rnmapbox/maps@10.2.7 in a React Native project with Node.js 22
  2. Configure Jest following the official documentation:
// jest.config.js
module.exports = {
  preset: 'jest-expo',
  setupFilesAfterEnv: ['@rnmapbox/maps/setup-jest'], // Recommended in docs
  transformIgnorePatterns: [
    'node_modules/(?!(@rnmapbox|...))',
  ],
};
  1. Run npm test
  2. Observe ERR_PACKAGE_PATH_NOT_EXPORTED error

Analysis

Node.js enforces the exports field in package.json strictly. The current exports field in v10.2.7:

"exports": {
  ".": { ... },
  "./package.json": "./package.json",
  "./app.plugin.js": "./app.plugin.js"
  // ❌ Missing: "./setup-jest": "./setup-jest.js"
}

The file setup-jest.js exists in the package root and is listed in the files array, but without an explicit export entry, Node.js 22 blocks the import.

Workaround

Use the full path to bypass the exports restriction:

  setupFilesAfterEnv: [
    '<rootDir>/node_modules/@rnmapbox/maps/setup-jest.js',
  ],

Suggested Fix

Add the missing export to package.json:

"exports": {
  ".": { ... },
  "./package.json": "./package.json",
  "./app.plugin.js": "./app.plugin.js",
  "./setup-jest": "./setup-jest.js"
}

This would allow the recommended configuration to work with modern Node.js versions while maintainin backward compatibility.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions