常见问题

Node.js Libraries containing invalid ESM code

请参阅 库包含无效的 ESM 中的解释和解决方案

Node.js 报错:

To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
import { SomeImport } from "some-library";
         ^^^^^^^^^^
SyntaxError: Named export 'SomeImport' not found. The requested module 'some-library' 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 'some-library';
const { SomeImport } = pkg;
Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'node_modules/some-library/dist/esm/some-file' imported from node_modules/some-library/dist/esm/index.js
Did you mean to import some-file.js?

Hydration mismatch

请参阅 Hydration Mismatch 中的解释和解决方案

Vue 报错(浏览器中):

[Vue warn]: Hydration text mismatch:
 - Client: "foo"
 - Server: "bar"
   at <SomeComponent>
   at <App>
Hydration completed but contains mismatches.

React 报错(浏览器中):

Warning: Text content did not match. Server: "foo" Client: "bar"
An error occurred during hydration. The server HTML was replaced with client content in <SomeComponent>.
Text content does not match server-rendered HTML.
Hydration failed because the initial UI does not match what was rendered on the server.
There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.