I did following steps
npm install moment --save
import moment from "moment"
When i want to import momentjs i get the following error:
Uncaught TypeError: Cannot assign to read only property 'clone' of object '#<Moment>' (moment.js:3837 )
moment version: ^2.22.1
I use webpack 4.
Trying to import like this also failed with the same error:
import moment from "moment/src/moment"
Can somebody help me? I really dont know how to solve this. My Webpack Config:
const path = require('path')
const BrowserSyncPlugin = require("browser-sync-webpack-plugin")
var webpack = require('webpack');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
module.exports = {
entry: './src/js/index.js',
output: {
path: path.resolve(__dirname, 'static'),
filename: 'monitor-bundle.js'
},
devtool: 'source-map',
mode: 'development',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.css$/,
}
]
},
watch: true,
plugins: [
new BrowserSyncPlugin({
watchOptions: {
poll: true
},
host: "localhost",
port: "1337",
proxy: "http://localhost:80/",
files: ["./static/monitor-bundle.js"],
open: true,
reloadDelay: 0,
reloadDebounce: 0,
browser: ["chromium", "google chrome"]
}),
new BundleAnalyzerPlugin(),
],
};
finally found the solution. Problem is that i imported another npm module where i found this:
Object.defineProperty(Array.prototype, "clone", {
value: function(){
return this.slice(0)
},
enumerable: false,
writable: false,
})
changing writable false to wirtable true solved the problem
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With