I'm trying to get Quill to work on my React app but depending on my webpack config it throws two errors:
Uncaught SyntaxError: Unexpected token import
or
Uncaught ReferenceError: React is not defined
Please note that I'm not using react-quill nor create-react-app.
Solving the first error produces another, I've read that I need to make an exception in webpack to allow it to import from quill folder.
exclude: /node_modules/
into
/node_modules(?!\/quill)/
Now it throws the second error.
My webpack config file:
module.exports = {
entry: [
'./src/index.js'
],
output: {
path: __dirname,
publicPath: '/',
filename: 'bundle.js'
},
module: {
loaders: [{
exclude: /node_modules(?!\/quill)/,
loader: 'babel',
query: {
presets: ['react', 'es2015', 'stage-1']
}
}]
},
resolve: {
extensions: ['', '.js', '.jsx']
},
devServer: {
historyApiFallback: true,
contentBase: './'
}
};
I'm using basic code from Quill docs to import what's needed:
import React, { Component } from 'react';
import Quill from 'quill/core';
import Toolbar from 'quill/modules/toolbar';
import Snow from 'quill/themes/snow';
import Bold from 'quill/formats/bold';
import Italic from 'quill/formats/italic';
import Header from 'quill/formats/header';
Quill.register({
'modules/toolbar': Toolbar,
'themes/snow': Snow,
'formats/bold': Bold,
'formats/italic': Italic,
'formats/header': Header
});
class Tutorial extends Component {
constructor(props){
super(props);
this.editor = null;
}
render(){
return (
<div className="verb-container">
<div className="editor"></div>
</div>
);
}
}
export default Tutorial;
When I import just:
import Quill from 'quill';
or
import Quill from 'quill/core';
A basic editor appears if I initialize it like this:
this.editor = new Quill('.editor');
But when I try to import
import Snow from 'quill/themes/snow';
It shows:
React is not defined
If I missed any important information, please let me know.