前端库使用问题记录

254 阅读1分钟

node-fetch v3版本 在node 12+环境中使用报错

问题描述:

[Error: require() of ES modules is not supported when importing node-fetch]

node-fetch v3 is ESM-only: github.com/node-fetch/….

The esm module you’re adding is for adding ESM compatibility, but it’s unnecessary now that Node 12+ supports ESM natively; and it doesn’t work with ESM-only packages like node-fetch 3+.

解决方案:

  1. Remove the esm package.
  2. Add "type": "module" to your package.json.

diff-match-patch && codeMirror windows系统报错

问题描述

cannot resovle diff_match_patch in codemirror/addon/merge.js

解决方案

  • 安装diff_match_patch
  • webpack ProvidePlugin插件定义
webpackConfig.plugins.push(
    new webpack.ProvidePlugin({
      diff_match_patch: ["diff_match_patch/lib/diff_match_patch", "diff_match_patch"],
      DIFF_EQUAL: ["diff_match_patch/lib/diff_match_patch", "DIFF_EQUAL"],
      DIFF_INSERT: ["diff_match_patch/lib/diff_match_patch", "DIFF_INSERT"],
      DIFF_DELETE: ["diff_match_patch/lib/diff_match_patch", "DIFF_DELETE"],
  })
);```