Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

照着官网运行直接报错 #37

Open
michael20102013 opened this issue May 20, 2021 · 2 comments
Open

照着官网运行直接报错 #37

michael20102013 opened this issue May 20, 2021 · 2 comments

Comments

@michael20102013
Copy link

wangchengxiang@wangchengxiang dxyer-v2-doc-repress % rcpress dev
internal/modules/cjs/loader.js:1154
throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/wangchengxiang/.config/yarn/global/node_modules/mdast-util-toc/index.js
require() of ES modules is not supported.
require() of /Users/wangchengxiang/.config/yarn/global/node_modules/mdast-util-toc/index.js from /Users/wangchengxiang/.config/yarn/global/node_modules/@rcpress/markdown/src/index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename /Users/wangchengxiang/.config/yarn/global/node_modules/mdast-util-toc/index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/wangchengxiang/.config/yarn/global/node_modules/mdast-util-toc/package.json.

at Object.Module._extensions..js (internal/modules/cjs/loader.js:1154:13)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Module.require (internal/modules/cjs/loader.js:1026:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/Users/wangchengxiang/.config/yarn/global/node_modules/@rcpress/markdown/src/index.js:2:21)
at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14) {

code: 'ERR_REQUIRE_ESM'
}

貌似一部分是用commjs的,一部分是es6的模块功能

@michael20102013
Copy link
Author

node 版本v12.18.1

@michael20102013
Copy link
Author

找到原因了,mdast-util-toc 6.0+只支持es module,可以暂时指定mdast-util-toc的版本为5.0+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant