[GH-ISSUE #362] Can't resolve markdown-it in Create-React-App #304

Closed
opened 2026-03-03 01:25:34 +03:00 by kerem · 5 comments
Owner

Originally created by @hamza1220 on GitHub (Jan 1, 2021).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/362

Error:
Module not found: Can't resolve 'markdown-it' in 'project/node_modules/markdownlint/lib'

Steps to reproduce:
npx create-react-app project
cd project
yarn add markdownlint
yarn && yarn start
Go to src/App.js and add the line import markdownlint from 'markdownlint'

node version v14.4.0
react version v17.0.1

The issue seems to be of the absolute import. In markdownlint.js, changing the absolute import const markdownIt = require("markdown-it"); to a relative import const markdownIt = require("../node_modules/markdown-it/index.js"); seems to fix the issue.

Originally created by @hamza1220 on GitHub (Jan 1, 2021). Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/362 **Error:** `Module not found: Can't resolve 'markdown-it' in 'project/node_modules/markdownlint/lib'` **Steps to reproduce:** `npx create-react-app project` `cd project` `yarn add markdownlint` `yarn && yarn start` Go to `src/App.js` and add the line `import markdownlint from 'markdownlint'` node version v14.4.0 react version v17.0.1 The issue seems to be of the absolute import. In `markdownlint.js`, changing the absolute import `const markdownIt = require("markdown-it");` to a relative import `const markdownIt = require("../node_modules/markdown-it/index.js");` seems to fix the issue.
kerem 2026-03-03 01:25:34 +03:00
Author
Owner

@DavidAnson commented on GitHub (Jan 1, 2021):

That's not how require is supposed to work. Could you try using npm instead of yarn?

https://nodejs.org/dist/latest-v14.x/docs/api/modules.html#modules_addenda_package_manager_tips

<!-- gh-comment-id:753344652 --> @DavidAnson commented on GitHub (Jan 1, 2021): That's not how `require` is supposed to work. Could you try using `npm` instead of `yarn`? https://nodejs.org/dist/latest-v14.x/docs/api/modules.html#modules_addenda_package_manager_tips
Author
Owner

@hamza1220 commented on GitHub (Jan 1, 2021):

I have also tried using npm but it still shows the same error. I understand that require isn't supposed to have relative imports, I'm just trying to point out that for some reason, the absolute import isn't working in react apps. The package unaltered currently doesn't work with a bare create-react-app

<!-- gh-comment-id:753372470 --> @hamza1220 commented on GitHub (Jan 1, 2021): I have also tried using `npm` but it still shows the same error. I understand that `require` isn't supposed to have relative imports, I'm just trying to point out that for some reason, the absolute import isn't working in react apps. The package unaltered currently doesn't work with a bare create-react-app
Author
Owner

@DavidAnson commented on GitHub (Jan 1, 2021):

Ok, thanks, I'll have a look when I get a chance. Are other uses of require also affected, or just this one?

<!-- gh-comment-id:753390050 --> @DavidAnson commented on GitHub (Jan 1, 2021): Ok, thanks, I'll have a look when I get a chance. Are other uses of `require` also affected, or just this one?
Author
Owner

@DavidAnson commented on GitHub (Jan 2, 2021):

This problem appears to be due to something in CRA (Webpack?) tripping up on the "browser" section in package.json:
github.com/DavidAnson/markdownlint@2a9274ece5/package.json (L71-L73)

That was added 6 years ago as part of configuring Browserify to produce a self-contained JS file for browser scenarios: github.com/DavidAnson/markdownlint@070eb19177

If you remove that section from project/node_modules/markdownlint/package.json, you should find that the app starts successfully.

I can maybe find a way to work around the incompatibility between those tools and remove that section from this project's configuration?

<!-- gh-comment-id:753425579 --> @DavidAnson commented on GitHub (Jan 2, 2021): This problem appears to be due to something in CRA (Webpack?) tripping up on the "browser" section in `package.json`: https://github.com/DavidAnson/markdownlint/blob/2a9274ece586514ba3e2819cec3eb74312dc1b84/package.json#L71-L73 That was added 6 years ago as part of configuring Browserify to produce a self-contained JS file for browser scenarios: https://github.com/DavidAnson/markdownlint/commit/070eb19177d8147da38cb8a86121f172334c5672 If you remove that section from `project/node_modules/markdownlint/package.json`, you should find that the app starts successfully. I can maybe find a way to work around the incompatibility between those tools and remove that section from this project's configuration?
Author
Owner

@hamza1220 commented on GitHub (Jan 3, 2021):

Removing that did work for me but since packages are downloaded fresh in the production environment, I still won't be able to use the package. I'd really appreciate it if you could find a way around this problem.

<!-- gh-comment-id:753661140 --> @hamza1220 commented on GitHub (Jan 3, 2021): Removing that did work for me but since packages are downloaded fresh in the production environment, I still won't be able to use the package. I'd really appreciate it if you could find a way around this problem.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/markdownlint#304
No description provided.