Two.js: ES Module build?

Created on 31 Jan 2018  路  6Comments  路  Source: jonobr1/two.js

I'd love it if this worked


import { Two } from 'https://cdnjs.cloudflare.com/ajax/libs/two.js/0.6.0/two.min.js';

Is there a way I can do an ES Module style import that I'm missing?

bug question

All 6 comments

Unfortunately v0.6.0 isn't ES Module compliant. This version should be though: https://cdnjs.cloudflare.com/ajax/libs/two.js/0.7.0-alpha.1/two.min.js

Sorry for the confusion!

Thanks for the response! I hadn't tried that, but now have. I went through several import syntax options without luck. See anything I'm doing wrong?

For reference this is all in Chrome 63 (latest as of writing)

import Two from 'https://cdnjs.cloudflare.com/ajax/libs/two.js/0.7.0-alpha.1/two.min.js';

Throws

Uncaught SyntaxError: The requested module does not provide an export named 'default'

import { Two } from 'https://cdnjs.cloudflare.com/ajax/libs/two.js/0.7.0-alpha.1/two.min.js';

throws

Uncaught SyntaxError: The requested module does not provide an export named 'Two'

import * as Two from 'https://cdnjs.cloudflare.com/ajax/libs/two.js/0.7.0-alpha.1/two.min.js';

throws

Uncaught TypeError: Cannot use 'in' operator to search for 'Array' in undefined
    at Object.$jscomp.polyfill (two.min.js:5)
    at two.min.js:5
$jscomp.polyfill @ two.min.js:5
(anonymous) @ two.min.js:5

import 'https://cdnjs.cloudflare.com/ajax/libs/two.js/0.7.0-alpha.1/two.min.js';

throws

Uncaught TypeError: Cannot use 'in' operator to search for 'Array' in undefined
    at Object.$jscomp.polyfill (two.min.js:5)
    at two.min.js:5
$jscomp.polyfill @ two.min.js:5
(anonymous) @ two.min.js:5

Oh shoot, sorry about this. The module must not be exporting properly... Unfortunately, I won't have a quick fix for this up. But, I am very close to releasing v0.7.0 at which point I'll make sure that it exports correctly.

No worries, thanks for the attention and the great library!

Okay, this commit fixes the issue: https://github.com/jonobr1/two.js/commit/9ab30a64b6f68cce60470b919ccecc77817ab40f

And you should be able to use this link to dynamically import Two.js: https://cdn.rawgit.com/jonobr1/two.js/dev/build/two.module.js

cdnjs will be updated once v0.7.0 is finished up and tagged. Soon I promise!

Awesome! Works! Thanks for the extremely quick fix.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

webenters picture webenters  路  6Comments

caracal7 picture caracal7  路  8Comments

trusktr picture trusktr  路  8Comments

mariomeraz picture mariomeraz  路  6Comments

EdeMeijer picture EdeMeijer  路  7Comments