Skip to content

Conversation

@monkey-denky
Copy link
Contributor

Cannot import from @apify/markdown in project with "type": "module". Minimal repo:

// package.json

{
  "name": "module-test",
  "main": "index.js",
  "type": "module",
  "scripts": {
    "start": "node index.js"
  },
  "dependencies": {
    "@apify/markdown": "^2.0.10"
  }
}
// index.js

import { apifyMarked } from "@apify/markdown"

console.log(apifyMarked)

Run script: npm run start

Error:

file:///Users/nguyendan/work/module/node_modules/@apify/markdown/index.mjs:99
import { Renderer, lexer, parser } from "marked";
                   ^^^^^
SyntaxError: Named export 'lexer' not found. The requested module 'marked' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'marked';
const { Renderer, lexer, parser } = pkg;

I have played around locally in node_modules and this should hopefully fix it.

Cannot import from `@apify/markdown` in project with `"type": "module"`. Minimal repo:

```
// package.json

{
  "name": "module-test",
  "main": "index.js",
  "type": "module",
  "scripts": {
    "start": "node index.js"
  },
  "dependencies": {
    "@apify/markdown": "^2.0.10"
  }
}
```

```
// index.js

import { apifyMarked } from "@apify/markdown"

console.log(apifyMarked)
```

Run script: `npm run start`

Error:
```
file:///Users/nguyendan/work/module/node_modules/@apify/markdown/index.mjs:99
import { Renderer, lexer, parser } from "marked";
                   ^^^^^
SyntaxError: Named export 'lexer' not found. The requested module 'marked' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'marked';
const { Renderer, lexer, parser } = pkg;
```

I have played around locally in `node_modules` and this should fix it.
@monkey-denky monkey-denky added bug Something isn't working. t-web Issues with this label are in the ownership of the web team. labels Oct 12, 2022
@monkey-denky monkey-denky added this to the 48th Sprint - Web team milestone Oct 12, 2022
@monkey-denky monkey-denky self-assigned this Oct 12, 2022
@B4nan B4nan merged commit b874fb4 into master Oct 12, 2022
@B4nan B4nan deleted the bug/importing-named-exports-from-commonjs branch October 12, 2022 22:03
monkey-denky added a commit that referenced this pull request Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working. t-web Issues with this label are in the ownership of the web team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants