module import/export issue
Marked version: 4.0.0
Describe the bug
I updated marked in our project from ^3.0.2 to 4.0.0 (before it worked fine), and after the update I get an error marked__WEBPACK_IMPORTED_MODULE_5___default(...) is not a function when using it. It seems that the module is no longer exported properly,
I tried to change the import import { marked } from 'marked' as well as using marked.parse() as shown in the readme, but that doesn't seem to help.
To Reproduce
Steps to reproduce the behavior:
Use a webpack/npm project, import by means of import marked from 'marked'. Use the marked() function.
It looks like somewhere in your code you are trying to import the default export like import marked from 'marked'.
Make sure you replace all occurrences with import { marked } from 'marked'
I'm using TypeScript and can also confirm that I am also experiencing the same issue on 4.0.0. I am importing it using import { marked } from "marked"; but getting 'marked' can only be imported using 'import marked = require("marked")' or a default import.. It is possible that I just need to wait until @types/marked is bumped up a major version though.
@UziTech I tried that but didn't work... @AlanMorel From the error it looks like a Webpack issue. It also shows in my unit tests which are .js files.
It seems unlikely to be a webpack-specific issue because the project I'm using Marked on is not using webpack at all.
It is possible that I just need to wait until
@types/markedis bumped up a major version though.
I have the same problem and @types/marked is still in 3.X
@types/marked v4 should be released soon
Great, I believe that update to @types/marked will resolve my issue, so I will wait for that, thanks!
Side question though: any reason marked itself is not providing the typings for the library? It would both eliminate needing a separate @types/marked dependency while also ensuring that you can bump both the library and typings at the same time. Not a huge deal though, just curious.
Also waiting for @types/marked ... Do you guys have a workaround or maybe I should go back to previous stable version?
Pretty sure your only options are wait for the updated types (which should be coming soon) or use a previous version.
Ok, thanks. If it is the typings that cause the issue though, is there any way to omit the blocking error for now? Such as placing a // @ts-ignore comment somewhere?
@paddotk If you are in a hurry you can always use gitpkg.now.sh and get an NPM package from the latest commit of UziTech's PR while waiting for it to be merged.
"@types/marked": "https://gitpkg.now.sh/UziTech/DefinitelyTyped/types/marked?415785793c958a98fa8902c482fe8be7959f86f6"
The types have been merged and it's looking good on my end now
It seems like v4.0.0 still doesn't work with Webpack. It looks like Webpack is trying to import lib/marked.cjs as an ES6 module. If I manually remove the "browser" settings in package.json or set it to be the same as "main", webpack works.
I guess this stems from the pre-ES6 module PR #1661, but I think it's safe to at least revert this PR for the short term until a better solution is available, if it causes webpack to not work at all...
looks like webpack suggests this fix.
@boazy if you want to test that out and create a PR for that we could get it merged in.
I'm also having issues. I'm not using webpack, typescript, babel or anything, just using ESM module to run my code in Express.
v3 works correctly, if I upgrade to v4 and switch my import from import marked from 'marked'; to import { marked } from 'marked'; I get the following error trying to run it:
/<path>/app/shared/text/format.js:1
Error [ERR_REQUIRE_ESM]: require() of ES Module /<path>/node_modules/marked/lib/marked.esm.js not supported.
Instead change the require of marked.esm.js in null to a dynamic import() which is available in all CommonJS modules.
I also have the same issue when using marked in CodeSandbox.
When using [email protected], and trying to import { marked } from 'marked (using the latest @types/[email protected]), marked is undefined. For now I've resorted to using [email protected] with import marked from 'marked. But it would e nice to have this fixed.
marked 4.0.1 has been released that may help with ESM instead of commonJS issues. The main entry in package.json now points to the commonJS code.
Real node ESM modules using babel will need to configure for it (unrelated to first comment).
It seems to fix my issue, thanks!
@webstech This still doesn't work for me:
const INITIAL_MARKED_OPTIONS = {
gfm: false,
headerIds: false,
}
// Reset Marked to the defaults and set custom options
marked.setOptions({
...marked.getDefaults(),
...INITIAL_MARKED_OPTIONS,
})

@webstech This still doesn't work for me:
Did you restart the editor? The types change requires that for some setups (vscode/eslint in my case). Are you getting compile errors? Pasted your code into mine and there were no complaints. _marked.marked does not show up in a search. Do you know where this is coming from?