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

NPM Package does not work. #658

Open
l-rojas opened this issue Jun 29, 2016 · 14 comments
Open

NPM Package does not work. #658

l-rojas opened this issue Jun 29, 2016 · 14 comments

Comments

@l-rojas
Copy link

l-rojas commented Jun 29, 2016

I was trying to install Mathquill as an NPM dependency, and, talking with Andrew Hyndman (@ajhyndman) on the Slack channel, he realized that the main script is not defined in package.js, which might be the issue.

@laughinghan
Copy link
Member

laughinghan commented Jun 29, 2016

I didn't see you guys chatting about it, where was that?

I assume by "does not work" you mean that you aren't able to require('mathquill') with Browserify or Webpack (if not, can you clarify?). Adding a "main" to package.json isn't enough, we'd also need to package it with CommonJS for you to be able to require() it.

My current plan is to switch to Rollup and have it output mathquill.common.js, mathquill.amd.js etc, because I think UMD is awful and brittle and unnecessary; but I'd be interested in hearing opinions on UMD.

@laughinghan
Copy link
Member

Someone came into Slack today to chat about this, and managed to use MathQuill with browserify-shim using the following config:

  "browserify-shim": {
    "mathquill": {
      "depends": ["./node_modules/jquery/dist/jquery.js:jQuery"],
      "exports": "MathQuill"
    }
  },

https://mathquill.slack.com/archives/mathquill/p1467223762000717

If you're using Browserify, let me know if that works for you

@rkotcher
Copy link

I was the one who was on slack earlier 😄 Let me know if I can be of help!

@isubasti
Copy link

@rkotcher I have never use browserify-shim before. Is there any other thing that I should do other than adding that config to package.json?

@jgable
Copy link

jgable commented Jan 27, 2017

I have a fork that I publish to npm with built files (good for webpack or browserify) https://github.com/FB-PLP/mathquill. It is published as node-mathquill and it mostly follows the versioning from this repo.

@viktorstrate
Copy link

If you are using webpack, you can use loaders to import mathquill, like @laughinghan explains, but with webpack instead.

Install the following loaders:

$ npm install --save-dev exports-loader imports-loader

Then you can import mathquill like this:

const MathQuill = require('exports-loader?window.MathQuill!imports-loader?window.jQuery=jquery!mathquill/build/mathquill.js')
const MQ = MathQuill.getInterface(2)

@gselvamary
Copy link

If you are using webpack, you can use loaders to import mathquill, like @laughinghan explains, but with webpack instead.

Install the following loaders:

$ npm install --save-dev exports-loader imports-loader

Still not working

@gselvamary
Copy link

Can anyone give me a link to take components to add equation in the text field

@gselvamary
Copy link

I am not using web pack .. can you guide

@viktorstrate
Copy link

@gselvamary I have made a React wrapper, which uses Webpack, take a look at how it's implemented react-mathquill.

@gselvamary
Copy link

@viktorstrate Hi... You did a great job.. I am working with your wrapper only.... I have the problem in this line
export const MathQuill = require('exports-loader?window.MathQuill!imports-loader?window.jQuery=jquery!mathquill/build/mathquill.js')

@gselvamary
Copy link

@viktorstrate I am not using web pack and yarn

@viktorstrate
Copy link

This method only works with Webpack, you need to use webpack to import it this way.
If not, why don't you use the traditional way of importing, as described here Gettings started - Mathquill docs.

If you have further questions please write to me at viktorstrate@gmail.com, to keep this thread focused on the original issue. 😉

@AlienKevin
Copy link

A more complete reference of viktorstrate's Webpack installation guide that includes required CSS file:

import { getInterface } from 'exports-loader?window.MathQuill!imports-loader?window.jQuery=jquery!mathquill/build/mathquill.js';
import "mathquill/build/mathquill.css";
const MQ = getInterface(2);
// start using mathquill
const mathField = MQ.MathField(document.getElementById("mathField"));

Remember to install exports and imports loader:

npm install --save-dev exports-loader imports-loader

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

8 participants