报错:Could not resolve "@turf/turf" node_modules/mars3d/dist/mars3d.js:10:151:

384 阅读1分钟

Could not resolve "@turf/turf"

node_modules/mars3d/dist/mars3d.js:10:151:
  10 │ ... && typeof module !== 'undefined' ? factory(exports, (window.Cesium || require('mars3d-cesium')), (window.turf || require('@turf/turf'))) :
     ╵                                                                                                                              ~~~~~~~~~~~~

You can mark the path "@turf/turf" as external to exclude it from the bundle, which will remove this error. You can also surround this "require" call with a try/catch block to handle this failure at run-time instead of bundle-time.

08:53:17 [vite] error while updating dependencies: Error: Build failed with 1 error: node_modules/mars3d/dist/mars3d.js:10:151: ERROR: Could not resolve "@turf/turf" at failureErrorWithLog (D:\project\tgkt-qt\node_modules\esbuild\lib\main.js:1649:15) at D:\project\tgkt-qt\node_modules\esbuild\lib\main.js:1058:25 at D:\project\tgkt-qt\node_modules\esbuild\lib\main.js:1525:9 at processTicksAndRejections (node:internal/process/task_queues:96:5)

image.png

这里重新拉取同事提交的代码项目运行项目时,出现了报错信息,查不到@turf/turf路径 解决方法:npm install --save @turf/turf mars3d-cesium 然后npm run dev,运行成功

image.png