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

Webpack? #99

Closed
anitagraham opened this issue Feb 27, 2019 · 11 comments
Closed

Webpack? #99

anitagraham opened this issue Feb 27, 2019 · 11 comments

Comments

@anitagraham
Copy link

Versions
roughjs@3.0.0
webpack@4.29.4

I am trying to use roughjs with webpack. (Actually using webpacker, as main app is a Rails application)

I have tried using rough.svg and rough.canvas, and I end up getting this error (or the same for canvas) every time:

TypeError: roughjs_dist_rough__WEBPACK_IMPORTED_MODULE_0___default.a.svg is not a function

from this:

import rough from "roughjs/dist/rough";
  return {
    bgFrame: (element) => {

      let svgBg = document.createElementNS("http://www.w3.org/2000/svg", "svg")
      **const rs = rough.svg(svgBg);**
      let frameWidth = element.width;
      let frameHeight = element.height;
      let node = rs.rectangle(0, 0, frameWidth, frameHeight, {fill: "red"}); 
      svgBg.appendChild(node);
    }
  }
}) ();
export default frame

called here:

 [...document.querySelectorAll('img.frame')].forEach(
    (image) => {
      frame.bgFrame(image)
    }
  )

I have tried several variations on this without luck.
I can create an svg without roughjs, and add it to the document.

Thanks for any thoughts on where I am going wrong.

@jeasonstudio
Copy link

Try this:

import rough from 'roughjs/dist/rough.umd';

@anitagraham
Copy link
Author

Thanks ... moving foward!

@pshihn
Copy link
Collaborator

pshihn commented Mar 11, 2019

Thanks for the help @jeasonstudio

@Cosmitar
Copy link

for roughjs v4.3.1

import rough from 'roughjs/bundled/rough.cjs';

@guimeisang
Copy link

for roughjs v4.3.1

import rough from 'roughjs/bundled/rough.esm.js' 

@pshihn
Copy link
Collaborator

pshihn commented Jul 2, 2020

A lot of it comes from the fact that webpack pays attention to the "browser" field in the package.json over "module" field.
Should remove browser from roughjs' package.json

@hamza1220
Copy link

I am working on a Next Js application and have tried both @guimeisang and @Cosmitar's solutions for roughjs v4.3.1. I get this error:

SyntaxError: Unexpected token 'export'
module.exports = require("roughjs/bundled/rough.esm.js");

@Rameshv
Copy link

Rameshv commented Jul 6, 2021

Its the same issue for me @hamza1220 . have you got it working with next??

@davincios
Copy link

I have the same issue with next

@davincios
Copy link

I have the same issue with next

@Rameshv did you get it to work with next?

@Jasurb3k-coding
Copy link

not working with React I believe.

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

9 participants