Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Merge requests
  • !8768

Add .cjs and .mjs files support to test runner

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/ai/fix/cjs-mjs-ext into master Apr 02, 2020
  • Overview 4
  • Commits 1
  • Pipelines 0
  • Changes 1

Created by: ai

Node.js added new .cjs and .mjs file extensions for dual ESM/CJS packages.

This PR adds .cjs and .mjs files from node_modules support to test runner.

Context

I have popular dual CJS/ESM package.

  "type": "module",
  "main": "index.cjs",
  "module": "index.js",
  "browser": {
    "./index.js": "./index.browser.js"
  },
  "exports": {
    ".": {
      "require": "./index.cjs",
      "import": "./index.js",
      "browser": "./index.browser.js"
    },

Everythings works in Create React App npm start:

import { nanoid } from 'nanoid'

But Jest can’t load my library during npm test:

TypeError: (0 , _nanoid.nanoid) is not a function

Here is issue in my repo: https://github.com/ai/nanoid/issues/205

The Way to Reproduce the Problem

  1. Create an empty CRA project
  2. npm i nanoid
  3. Create test:
    import * as nanoid from 'nanoid'
    console.log(nanoid)

Right now output will be:

{ default: 'index.cjs' }

With this pull request the result will be correct:

{ nanoid: [Function nanoid], urlAlphabet: …, customAlphabet: …, customRandom: … }
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/ai/fix/cjs-mjs-ext