Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Cannot read property 'createSESInThisRealm' of undefined #163

Closed
steve8708 opened this issue Feb 22, 2019 · 3 comments · Fixed by Agoric/SES#97
Closed

Comments

@steve8708
Copy link

I'm very excited about this project and eager to use it, but I get an error every time:

I am using ses@0.4.0 with typescript 3 and webpack 4

My code is:

export function safeEvaluate(code: string, context?: {}): any {
  const realm = SES.makeSESRootRealm();
  try {
    return realm.evaluate(code, context);
  } catch (err) {
    console.warn('Evaluation error:', err);
  }
}

And when running anything, e.g.

safeEvaluate('a + 2', { a: 1 })

I get:

Uncaught TypeError: Cannot read property 'createSESInThisRealm' of undefined

I am running this in Chrome 72.0.3626.96

@katelynsills
Copy link
Contributor

Hi Steve, I'm trying to reproduce the issue here, but haven't been able to so far. I have ses@0.4.0, typescript 3, and webpack 4 installed, and then I do npm run build and open the index.html file in Chrome 72.0.3626.109. Does anything stick out to you as different than how you have things set up?

Thanks again for filing the issue!

@steve8708
Copy link
Author

Of course! So I tried this in a range of setups and get errors every time - here are some examples

Codesandbox example with parcel and babel yields TypeError Cannot read property 'package' of undefined
Stackblitz example webpack and babel yields Import error, can't find file: ./common
Git repo generated with create-react-app (see index.js) yields ReferenceError: esm_createClass is not defined

I also tried chagning import * as SES from 'ses' to
import SES from 'ses'
import * as SES from 'ses/src/index.js'
import * as SES from 'ses/src/commonjs-index.js'
import * as SES from 'ses/src/dist/ses-shim.js'
in each of the example and all have different errors

It seems that the project from it's default imports is not prebuilt in a way that is compatible with a lot of build tools, and the one prebuilt example in dist is only for browsers and cannot be used with modern module loaders since it uses a global variable.

It seems to me this project just needs a CJS/ESM distribution build, e.g. with rollup, and ideally the package.json main, module, and browser fields would point to the prebuilt dist versions so module bundlers will load the correct one.

I just peeked that you do use rollup but only generate just an iife bundle, but leave everyone else to point to your raw source which causes issues with lots of build tools.

If you just add a couple configs like this example I think all of your problems should be solved.

I've done this for all of the modules in builder and it works well, i'll send a PR shortly for this project that'll do the same

@steve8708
Copy link
Author

Create PR over here

@jfparadis jfparadis transferred this issue from Agoric/SES Feb 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants