lukehaas / RunJS

RunJS is a JavaScript playground for macOS, Windows and Linux. Write code with instant feedback and access to Node.js and browser APIs.
https://runjs.app
2k stars 43 forks source link

Bug: import statement is not working #597

Closed ESnark closed 6 months ago

ESnark commented 6 months ago

I have no idea which packages are affected by this issue, but surely luxon is.

I've added luxon and @types/luxon and the runjs prompt a TypeError.

import luxon from 'luxon'

// TypeError: Cannot read properties of undefined (reading 'DateTime')
luxon.DateTime.local({ zone: 'Asia/Seoul' }).toFormat('yyyyMMdd');
// This works but the editor complains that It is not an import
const luxon = require('luxon');

luxon.DateTime.local({ zone: 'Asia/Seoul' }).toFormat('yyyyMMdd');
lukehaas commented 6 months ago

@ESnark this is due to the way exports are handled in the luxon library. Try it this way:

import * as luxon from 'luxon'

luxon.DateTime.local({ zone: 'Asia/Seoul' }).toFormat('yyyyMMdd');
ESnark commented 6 months ago

There are some differences from my dev environment but it's acceptible. Thank you 👍