"ReferenceError: base is not defined" when no 'use strict' pragma. #2

Closed
opened 2016-12-02 23:54:04 +01:00 by radicaled · 3 comments
radicaled commented 2016-12-02 23:54:04 +01:00 (Migrated from github.com)

I'm integrating Prosemirror into an Electron application, and I've discovered that pressing a modifier key generates this error: Uncaught ReferenceError: base is not defined at this location: github.com/marijnh/w3c-keyname@a8d1819f9c/index.js (L105)

This baffled me quite a bit, since I turned on DevTools and base is clearly in scope when the exception is raised. However, I discovered that adding the 'use strict' pragma to the first line of index.js seems to fix the issue.

I'm using Babel with Webpack + Vue.js, and my ProseMirror code is this:

      const EditorState = require('prosemirror-state').EditorState
      const EditorView = require('prosemirror-view').EditorView
      const schema = require('prosemirror-schema-basic').schema

      // Plugins
      const history = require('prosemirror-history')
      const keymap = require('prosemirror-keymap').keymap

      this.$nextTick(() => { // $nexkTick ensures the DOM element has been mounted and is ready
        const view = new EditorView(this.$el, {
          state: EditorState.create({
            schema: schema,
            plugins: [
              history.history(),
              keymap({
                'Mod-z': history.undo,
                'Mod-y': history.redo
              })
            ]
          }),
          onAction: (action) => {
            view.updateState(view.state.applyAction(action))
          }
        })

Basically following the ProseMirror "Getting Started" guide.

I'm integrating Prosemirror into an Electron application, and I've discovered that pressing a modifier key generates this error: `Uncaught ReferenceError: base is not defined` at this location: https://github.com/marijnh/w3c-keyname/blob/a8d1819f9c2c757628de7cc79e35013306c7e906/index.js#L105 This baffled me quite a bit, since I turned on DevTools and `base` is clearly in scope when the exception is raised. However, I discovered that adding the `'use strict'` pragma to the first line of index.js seems to fix the issue. I'm using Babel with Webpack + Vue.js, and my ProseMirror code is this: ```javascript const EditorState = require('prosemirror-state').EditorState const EditorView = require('prosemirror-view').EditorView const schema = require('prosemirror-schema-basic').schema // Plugins const history = require('prosemirror-history') const keymap = require('prosemirror-keymap').keymap this.$nextTick(() => { // $nexkTick ensures the DOM element has been mounted and is ready const view = new EditorView(this.$el, { state: EditorState.create({ schema: schema, plugins: [ history.history(), keymap({ 'Mod-z': history.undo, 'Mod-y': history.redo }) ] }), onAction: (action) => { view.updateState(view.state.applyAction(action)) } }) ``` Basically following the ProseMirror "Getting Started" guide.
marijnh commented 2016-12-03 08:13:43 +01:00 (Migrated from github.com)

Hi, could you paste your bundled code (or a simplified version of it) somewhere and link it? Even with the 'use strict' thing, I still can't understand how this is happening.

Hi, could you paste your bundled code (or a simplified version of it) somewhere and link it? Even with the 'use strict' thing, I still can't understand how this is happening.
marijnh commented 2016-12-03 10:25:40 +01:00 (Migrated from github.com)

Could this have actually been related to the code using const and Electron running an old V8 that didn't support const/let in non-strict scopes yet? See 92444b454b

Could this have actually been related to the code using `const` and Electron running an old V8 that didn't support const/let in non-strict scopes yet? See 92444b454b
radicaled commented 2016-12-03 15:05:24 +01:00 (Migrated from github.com)

@marijnh

That seems to have been it -- I made that change locally and everything works as expected now.

@marijnh That seems to have been it -- I made that change locally and everything works as expected now.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
marijn/w3c-keyname#2
No description provided.