mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2026-04-26 01:36:03 +03:00
[GH-ISSUE #362] Can't resolve markdown-it in Create-React-App #2152
Labels
No labels
bug
enhancement
enhancement
enhancement
fixed in next
fixed in next
fixed in next
new rule
new rule
new rule
pull-request
question
refactoring
refactoring
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/markdownlint#2152
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 projectcd projectyarn add markdownlintyarn && yarn startGo to
src/App.jsand add the lineimport 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 importconst markdownIt = require("markdown-it");to a relative importconst markdownIt = require("../node_modules/markdown-it/index.js");seems to fix the issue.@DavidAnson commented on GitHub (Jan 1, 2021):
That's not how
requireis supposed to work. Could you try usingnpminstead ofyarn?https://nodejs.org/dist/latest-v14.x/docs/api/modules.html#modules_addenda_package_manager_tips
@hamza1220 commented on GitHub (Jan 1, 2021):
I have also tried using
npmbut it still shows the same error. I understand thatrequireisn'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@DavidAnson commented on GitHub (Jan 1, 2021):
Ok, thanks, I'll have a look when I get a chance. Are other uses of
requirealso affected, or just this one?@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@070eb19177If 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?
@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.