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

Unable to import simple-dom with typescript and webpack #74

Open
reconbot opened this issue Feb 7, 2019 · 3 comments
Open

Unable to import simple-dom with typescript and webpack #74

reconbot opened this issue Feb 7, 2019 · 3 comments

Comments

@reconbot
Copy link

reconbot commented Feb 7, 2019

I'm trying to get simpledom working in codebase with two environments. One with ts-node and another with webpack and ts-loader with "esModuleInterop": true,

With simple-dom@1.3.0 I could do

import { Document, HTMLSerializer } from 'simple-dom'

And it worked in all environments but has a bug where I had to include dom in my tsconfig libs configuration to get typescript to compile.

For the upgrade to 1.4.0, the previous code works with ts-node but webpack changes the export from simple-dom to be a single export named simple-dom

This works but only in webpack with ts-loader@5.3.3 and not with ts-node

const {
  simpleDom: { Document, HTMLSerializer },
} = require('simple-dom')

The following work with nothing... errors are from webpack.

import simpleDom from 'simple-dom'
console.log({ simpleDom })
// { simpleDom: undefined }
import { simpleDom } from 'simple-dom'
console.log({ simpleDom })
// { simpleDom: undefined }
import simpledom from 'simple-dom/dist/modules/es2017'
console.log({ simpledom })
// { simpledom: undefined }
import { Document, HTMLSerializer } from 'simple-dom/dist/modules/es2017'
// [2019-02-07T17:44:36.740Z] ERROR (gradius): a.HTMLSerializer is not a constructor
//    TypeError: a.HTMLSerializer is not a constructor
//        at Object.<anonymous> (/Users/wizard/src/gradius/dist/webpack-test/index.js:1493:696)

I'm not sure where to go from here. Any ideas?

Thanks!

@reconbot
Copy link
Author

reconbot commented Feb 7, 2019

We got a workaround by requiring the dependent packages specifically.

import Document from '@simple-dom/document'
import HTMLSerializer from '@simple-dom/serializer'
import voidMap from '@simple-dom/void-map'

@imakeinterfaces
Copy link

Thanks, i had the same issue.

@stephankaag
Copy link

I run into the same issue. Is any better solution available in the meantime?

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

No branches or pull requests

3 participants