wangeditor5 Import and Run Error: You may need an appropriate loader to handle this file type (es6 compatibility issues)
Recently upgraded the rich text wangeditor used, I upgraded to the latest version of wangeditor5
Introduced wangeditor5 into the vue project, Starting the project has been reporting errors
You may need an appropriate loader to handle this file type
At first, I tried many methods but failed to solve it, Later I noticed an error reported in the console, Guess it may be related to the writing method of (…) in es6, So I will make a specific query later I took a look at the issue of compatibility with es6, I learned that webpack can only process a part of ES6 syntax, some more advanced ES6 syntax cannot be processed,Need to do compatibility processing.
Solution
1. Install the babel-polyfill es6-promise package
npm i babel-polyfill es6-promise --save
2. Add the following codes to main.js:
import 'babel-polyfill' //Note: This import should be before import Vue from 'vue'
import Vue from 'vue'
import Es6Promise from 'es6-promise'
Es6Promise.polyfill()
3. Add the following codes to webpack.base.conf.js:
module.exports = {
...
entry: {
app: ["babel-polyfill", "./src/main .js"]
},
...
}
Because wangeditor5 is a third-party dependency, in node_modules, and babel-polyfill does not detect es6, in node_modules, we need to add it manually.
Note:If you do not configure es6 compatibility for third-party dependencies,You can ignore the fourth step,You can run the startup project after the third step directly
4. In the webpack.base.conf.js file, modify the configuration of babel-loader, add a configuration item: resolve(‘node_modules/@wangeditor’ )(It needs to be modified according to the third-party dependencies actually introduced)
{
test: /\.js$/,
loader: 'babel-loader' ,
include: [resolve('src'), resolve( 'test'), resolve('node_modules/@wangeditor' ), resolve('node_modules/webpack-dev-server/client')]
},
Finally restart the project to be successful!
Read More:
- Vue Cli error: vuecliYou may need an additional loader to handle
- The browser is compatible with IE11 “ReferenceError: ‘Promise’ is not defined” “ReferenceError: ‘Promise’ is not defined”
- Solve the VUE startup problem (You may use special comments to disable some warnings)
- How to Solve Altium designer Rule Check Without an Error Issue
- [Solved] Faceswap Error: CRITICAL An unexpected crash has occurred.You MUST provide this file if seeking assistan
- [Solved] pagehelper Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘LIMIT 1’
- [Solved] TypeError: super(type, obj): obj must be an instance or subtype of type
- Vue require Error: node_modules/babel-loader/lib
- Vue el-table Error: Duplicated keys detected This may casuse an update error
- Report Duplicate keys detected: ‘0’. This may cause an update error in VUE and the solution
- [Solved] Postcss Error: Invalid options object. PostCSS Loader has been initialized using an options object that does not match the API schema.
- How to Solve Hmaster hangs up issue due to namenode switching in Ha mode
- [Solved] Unity3d reports an error using the opencv plug-in: unsafe code may only appear if compiling with/unsafe.
- TensorFlow issue: Expected int32, got list containing Tensors of type ‘_Message’ instead.
- There was an unexpected error (type=Method Not Allowed, status=405). Request
- [Solved] Windows Nginx Startup Error: bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a socket
- Error while trying to run project:unable to start debugging.the debugger is not properly installed. run setup to install or repa
- [Solved] github Error: ERROR: You‘re using an RSA key with SHA-1
- Proguard Packaging Error: You have to specify ‘-keep‘ options if you want to write out kept elements with ‘-print
- [Solved] The method getContextPath() from the type HttpServletRequest refers to the missing type String