I imported the Cesium module using ES6, as follows:
import * as Cesium from ‘cesium/Cesium’;
The error message is as follows:
TS2307: Cannot find module ‘cesium/Cesium’ or its corresponding type declarations.
Project dependencies are as follows:
cesium: 1.75.0
webpack: 5.39.1
react:17.0.2
typescript: 4.3.5
The configuration of WebPack is as follows:
const cesiumSource = ‘node_modules/cesium/Source’;
const cesiumWorkers = ‘…/Build/Cesium/Workers’;
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: ‘./src/index.html’
}),
new CopyWebpackPlugin({
patterns: [
{ from: path.join(cesiumSource, cesiumWorkers), to: ‘Workers’ },
{ from: path.join(cesiumSource, ‘Assets’), to: ‘Assets’ },
{ from: path.join(cesiumSource, ‘Widgets’), to: ‘Widgets’ },
]
}),
new webpack.DefinePlugin({
CESIUM_BASE_URL: JSON.stringify(’’)
})
],
output: {
filename: ‘[name].bundle.js’,
path: path.resolve(__dirname, ‘…/’, ‘build’),
sourcePrefix: ‘’,
},
amd: {
toUrlUndefined: true,
},
resolve: {
extensions: [’.js’, ‘.json’, ‘.sass’, ‘.scss’, ‘.less’, ‘jsx’, ‘.ts’, ‘.tsx’],
alias: {‘cesium’: path.resolve(cesiumSource)},
},
The configuration of TS is as follows
{
“compilerOptions”: {
“outDir”: “./dist/”,
“noImplicitAny”: true,
“module”: “commonjs”,
“target”: “esnext”,
“jsx”: “react”,
“allowJs”: true,
“sourceMap”: true,
“strict”: true,
“forceConsistentCasingInFileNames”: true,
“allowSyntheticDefaultImports”: true,
“moduleResolution”: “node”,
“types”: [
“node”,
“cesium”
],
},
“include”: [“src”],
“exclude”: [
“node_modules”
]
}