最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to force the import yjs module using mjs - Stack Overflow

programmeradmin4浏览0评论

My project using mjs style, I import the yjs("yjs": "^13.6.23") / in my project like this:

import * as Y from "yjs";

from the error info, I found the project using the yjs cjs code:

│ Caught error while handling a Yjs update TypeError: Cannot read properties of undefined (reading 'splice')                              │
│     at splitItem (/home/node/app/node_modules/yjs/dist/yjs.cjs:9606:22)                                                                 │
│     at getItemCleanEnd (/home/node/app/node_modules/yjs/dist/yjs.cjs:3007:34)                                                           │
│     at Item.getMissing (/home/node/app/node_modules/yjs/dist/yjs.cjs:9892:19)                                                           │
│     at integrateStructs (/home/node/app/node_modules/yjs/dist/yjs.cjs:1615:35)                                                          │
│     at /home/node/app/node_modules/yjs/dist/yjs.cjs:1698:25                                                                             │
│     at transact (/home/node/app/node_modules/yjs/dist/yjs.cjs:3444:14)                                                                  │
│     at readUpdateV2 (/home/node/app/node_modules/yjs/dist/yjs.cjs:1686:3)                                                               │
│     at applyUpdateV2 (/home/node/app/node_modules/yjs/dist/yjs.cjs:1781:3)                                                              │
│     at Object.applyUpdate (/home/node/app/node_modules/yjs/dist/yjs.cjs:1795:58)                                                        │
│     at readSyncStep2 (/home/node/app/node_modules/y-protocols/dist/sync.cjs:107:18)

I search the yjs dist folder, it contains both cjs amd mjs code, is it possible to force the yjs using mjs code, not use the cjs? This is my project package.json:

{
  "name": "texhub-broadcast",
  "version": "1.0.29",
  "description": "",
  "main": "./dist/app.js",
  "module": "./dist/app.js",
  "types": "./dist/app.d.ts",
  "type": "module",
  "exports": {
    "./dist/websocket/conn/socket_io_client_provider": "./dist/websocket/conn/socket_io_client_provider.js",
    ".": {
      "import": "./dist/app.js"
    }
  },
  "files": [
    "dist/*"
  ],
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "lint": "eslint --fix",
    "dev": "export NODE_ENV=dev && ts-node -r tsconfig-paths/register src/app.ts",
    "build": "tspc"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@socket.io/admin-ui": "^0.5.1",
    "dotenv": "^16.4.7",
    "esm-module-alias": "^2.2.1",
    "express": "^4.21.2",
    "flatted": "^3.3.2",
    "globals": "^15.14.0",
    "jsonwebtoken": "^9.0.2",
    "level": "^9.0.0",
    "leveldown": "^6.1.1",
    "levelup": "^5.1.1",
    "lib0": "^0.2.99",
    "lodash": "^4.17.21",
    "log4js": "^6.9.1",
    "meilisearch": "^0.35.1",
    "module-alias": "^2.2.3",
    "pg": "^8.13.3",
    "prom-client": "^14.2.0",
    "redis": "^4.7.0",
    "socket.io": "^4.8.1",
    "socket.io-client": "^4.8.1",
    "uuid": "^11.1.0",
    "ws": "^8.18.0",
    "y-leveldb": "^0.1.2",
    "y-protocols": "^1.0.6",
    "y-websocket": "^1.5.0",
    "yjs": "^13.6.23"
  },
  "devDependencies": {
    "@types/express": "^5.0.0",
    "@types/jsonwebtoken": "^9.0.8",
    "@types/lodash": "^4.17.15",
    "@types/node": "^22.13.8",
    "@types/pg": "^8.11.11",
    "@types/ws": "^8.5.14",
    "@typescript-eslint/eslint-plugin": "^8.22.0",
    "@typescript-eslint/parser": "^8.22.0",
    "eslint": "^9.19.0",
    "ts-node": "^10.9.2",
    "ts-patch": "^3.3.0",
    "tsc-alias": "^1.8.10",
    "tsconfig-paths": "^4.2.0",
    "typescript": "^5.7.3",
    "typescript-transform-paths": "^3.5.3",
    "vite": "^6.0.11",
    "vite-node": "^3.0.4",
    "vitest": "^3.0.4"
  }
}
发布评论

评论列表(0)

  1. 暂无评论