Import into ES6

This is more of a general JS question, but I haven’t really found good answers to this. So far I seem to always be able to import AMD modules from other, non-ES6 packages into an ES6 project by trying a variety of different things.

But what’s the recommended way of doing it in ProseMirror?

In the case of ProseMirror, the simple case such as:

var EditorState = require("prosemirror-state").EditorState

turns into

import {EditorState} from "prosemirror-state"


What about

var history = require("prosemirror-history")

is this

import * as history from "prosemirror-history"



const {Schema} = require("prosemirror-model")

turns into

import * as Schema from "prosemirror-model"


Is there a particular reason why history and Schema are being exported differently than the other things, or I am just not reading the code right?

There is nothing different about the way Schema and History are being exported. import {Schema} from "prosemirror-model" should work just fine (assuming your loader/bundler supports importing CommonJS with ES6 syntax, which I guess it does from your other examples).

Hmm, thanks.

I realized I could import the individual functions from history and schema also worked after a while. But somehow keymaps refuses to be imported in the same way. This seems to be working for me now:

import {EditorState} from "prosemirror-state"
import {EditorView} from "prosemirror-view"
import {keymap} from "prosemirror-keymap/dist/keymap"
import {history, redo, undo} from "prosemirror-history"
import {toggleMark} from "prosemirror-commands"
import {marks} from "prosemirror-schema-basic"
import {Schema} from "prosemirror-model"