Skip to content

@mdx-js/loader v1 does not work with yarn pnp or pnpm #2019

Closed as not planned
@anomiex

Description

@anomiex

Initial checklist

Affected packages and versions

1.6.22

Link to runnable example

No response

Steps to reproduce

  1. Use this project.
  2. Run one of the following commands
    • pnpm install && pnpm build
    • yarn set version stable && yarn install && yarn build
    • yarn install --pnp && yarn build

The problem seems to be that

const DEFAULT_RENDERER = `
import React from 'react'
import { mdx } from '@mdx-js/react'
`

assumes that @mdx-js/react will have been hoisted into the project's node_modules directory so webpack can find it when processing the transformed file later. Changing that to

const DEFAULT_RENDERER = ` 
import React from ${ JSON.stringify( require.resolve( 'react' ) ) }
import { mdx } from ${ JSON.stringify( require.resolve( '@mdx-js/react' ) ) }
`

makes it work (at least in pnpm).

I note this problem doesn't seem to occur with version 2.0.0 or later. However, I'm not using @mdx-js/loader directly, I'm using it via @storybook/addon-docs which still depends on @mdx-js/loader ^1.6.22, so updating to v2 is not currently an option.

Expected behavior

Project should build without error.

Actual behavior

Build fails with this error

ERROR in ./test.mdx 4:0-36
Module not found: Error: Can't resolve '@mdx-js/react' in '/tmp/test'
resolve '@mdx-js/react' in '/tmp/test'
  Parsed request is a module
  using description file: /tmp/test/package.json (relative path: .)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      looking for modules in /tmp/test/node_modules
        single file module
          using description file: /tmp/test/package.json (relative path: ./node_modules/@mdx-js/react)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /tmp/test/node_modules/@mdx-js/react doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /tmp/test/node_modules/@mdx-js/react.js doesn't exist
            .json
              Field 'browser' doesn't contain a valid alias configuration
              /tmp/test/node_modules/@mdx-js/react.json doesn't exist
            .wasm
              Field 'browser' doesn't contain a valid alias configuration
              /tmp/test/node_modules/@mdx-js/react.wasm doesn't exist
        /tmp/test/node_modules/@mdx-js/react doesn't exist
      /tmp/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory

Runtime

Node v16

Package manager

yarn v3, yarn v1, pnpm

OS

Linux

Build and bundle tools

webpack

Metadata

Metadata

Assignees

No one assigned

    Labels

    👎 phase/noPost cannot or will not be acted on💎 v1Issues related to v1🙅 no/wontfixThis is not (enough of) an issue for this project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions