前言
最近新入職了一家公司,公司新開了有個未來城市的項目,需要用到3D城市建模,公司老總選了Mars3d作為前端框架,項目分給我了,又是一個全新的領(lǐng)域,開搞吧!
下面是自己遇到的幾個小問題,記錄一下:
- 1 npm install copy-webpack-plugin --save -dev 時報錯
解決辦法:npm install copy-webpack-plugin --save -dev --legacy-peer-deps
-
2 第二個小錯誤就是很簡單的粗心了,報錯代碼:const path = require(‘path’)SyntaxError: Identifier ‘path’ has already been declared解決辦法:檢查一下代碼,就是自己多寫了一遍這個聲明語句,把重復(fù)的代碼刪除就好了。
-
3 ERROR TypeError: compilation.getCache is not a function
解決辦法:出現(xiàn)這個錯誤一般是我們的webpack和copy-webpack-plugin的版本不匹配導(dǎo)致的,這個時候我們只需要刪除自己的copy-webpack-plugin,然后安裝一個低版本的即可(這可能是第一個問題安裝的后遺癥)
兩條指令:卸載:npm uninstall copy-webpack-plugin,安裝:我安裝的是copy-webpack-plugin@5.0.0,我的webpack版本是 -
4 ERROR Error: [copy-webpack-plugin] patterns must be an array
解決辦法:這個是說我們的配置 new CopyWebpackPlugin()的參數(shù)必須是一個數(shù)組,我們從官網(wǎng)拷貝過來的代碼好像是
new CopyWebpackPlugin({
patterns: [
{ from: path.join(cesiumSourcePath, 'Workers'), to: path.join(config.output.path, cesiumRunPath, 'Workers') },
{ from: path.join(cesiumSourcePath, 'Assets'), to: path.join(config.output.path, cesiumRunPath, 'Assets') },
{ from: path.join(cesiumSourcePath, 'ThirdParty'), to: path.join(config.output.path, cesiumRunPath, 'ThirdParty') },
{ from: path.join(cesiumSourcePath, 'Widgets'), to: path.join(config.output.path, cesiumRunPath, 'Widgets') }
]
}),
改成這樣就好了
new CopyWebpackPlugin([
{ from: path.join(cesiumSourcePath, 'Workers'), to: path.join(config.output.path, cesiumRunPath, 'Workers') },
{ from: path.join(cesiumSourcePath, 'Assets'), to: path.join(config.output.path, cesiumRunPath, 'Assets') },
{ from: path.join(cesiumSourcePath, 'ThirdParty'), to: path.join(config.output.path, cesiumRunPath, 'ThirdParty') },
{ from: path.join(cesiumSourcePath, 'Widgets'), to: path.join(config.output.path, cesiumRunPath, 'Widgets') }
]
)
-
5
These dependencies were not found:
@turf/turf in ./node_modules/mars3d/dist/mars3d.js
*mars3d-cesium in ./node_modules/mars3d/dist/mars3d.js, ./src/main.js
To install them, you can run: npm install --save @turf/turf mars3d-cesium
這個很簡單就跟著運行這條指令就好了。 npm install --save @turf/turf mars3d-cesium文章來源:http://www.zghlxwxcb.cn/news/detail-447865.html -
6 Syntax Error: TypeError: Cannot read properties of undefined (reading ‘parseComponent’)
解決辦法:這個問題是vue與vue-template-compiler版本不一致導(dǎo)致的文章來源地址http://www.zghlxwxcb.cn/news/detail-447865.html
"vue": "2.7.14",
"vue-template-compiler": "^2.6.14"
- 7 Failed to compile. ./node_modules/mars3d-cesium/Build/Cesium/index.js 75:1800
解決辦法:這個是mars3d-cesuim版本問題,固定mars3d-cesium版本為1.95,“mars3d-cesium”: “1.95.1” 【注意不要^】
可以參考一下「小小的杰茜」的原創(chuàng)文章
到了這里,關(guān)于Mars3d項目啟動上的一些坑的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!