Skip to content

Instantly share code, notes, and snippets.

Avatar

Gil Tayar giltayar

View GitHub Profile
View main(CJS).js
const {kettle} = require('./kettle.mjs') // fails with error
console.log(kettle)
View .babelrc
{
"plugins": [
"transform-es2015-modules-commonjs", "dynamic-import-node"
]
}
View esm-dual-mode-package.json
{
"name": "dual-cjs-mjs-package",
"version": "1.0.0",
"description": "A package that can be both imported as esm and as cjs",
"main": "entry",
"scripts": {
"build": "babel *.mjs **/*.mjs --out-dir ."
},
"devDependencies": {
"babel-cli": "^6.26.0",
View main(ESM)-2.mjs
import kettleModule from './kettle.js' // succeeds
console.log(kettleModule.kettle)
View main(ESM).mjs
const {kettle} = require('./kettle.js') // fails with error
console.log(kettle)
View main(CJS)-2.js
import {kettle} from './02-kettle.mjs' //fails with error
console.log(kettle)
View main(CJS)-3.js
async function main() {
const {kettle} = await import('./kettle.mjs') // succeeds!
console.log(kettle)
}
main()
View 01-main.mjs
import {handle, spout, tea} from './01-kettle.mjs'
console.log(handle) // ==> the handle
console.log(spout) // ==> the spout
console.log(tea) // ==> hot tea
View 01-kettle.mjs
export const spout = 'the spout'
export const handle = 'the handle'
export const tea = 'hot tea'
View todo-list(eyes).test.js
const webdriver = require('selenium-webdriver')
const {By, until} = webdriver
const {Eyes} = require('eyes.selenium')
require('chromedriver')
describe.only('todo list', function() {
jest.setTimeout(30000)
let driver
beforeAll(async () => (driver = await new webdriver.Builder().forBrowser('chrome').build()))