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 support #34

Closed
philippkuehn opened this issue Feb 8, 2018 · 5 comments
Closed

Webpack support #34

philippkuehn opened this issue Feb 8, 2018 · 5 comments
Labels
🙋 no/question This does not need any changes

Comments

@philippkuehn
Copy link

Your basic markdown example isn't working in a browser.

var unified = require('unified');
var markdown = require('remark-parse');
var remark2rehype = require('remark-rehype');
var doc = require('rehype-document');
var format = require('rehype-format');
var html = require('rehype-stringify');

unified()
  .use(markdown)
  .use(remark2rehype)
  .use(doc)
  .use(format)
  .use(html)
  .process('# Hello world!')
  .then(function (file) {
    console.log(String(file));
  }, function (err) {
    console.error(String(err));
  });

I will get an error

ReferenceError: process is not defined
    at new VFile (VM11132 core.js:47)
    at VFile (VM11132 core.js:41)
    at executor (VM11126 index.js:369)
    at Function.process (VM11126 index.js:366)

The problem is this line in vfile

this.cwd = process.cwd();

When commenting this line out everything is fine. Is this the expected behavior? I don't see anything in the docs that unified is only made for node.

@wooorm
Copy link
Member

wooorm commented Feb 8, 2018

Yes, it should work, but it looks like the tool you use to build JavaScript (webpack? rollup? browserify) is not configured to include native node modules. This really depends on the tool you’re using, so you’ll probably fare best by checking with them!

@wooorm wooorm closed this as completed Feb 8, 2018
@philippkuehn
Copy link
Author

Ah okay. Maybe that is some information for the documentation? Do you have an example how to use it with webpack? I can't get it to work :/

@cloverich
Copy link

@philippkuehn I'm sure you figured this out by now, but by default webpack adds and bundles Node dependencies when the target is web (the default, see webpack's target documentation).

@DrewHoo
Copy link

DrewHoo commented Jun 12, 2019

I'm hitting this issue, too while serving an Angular app (I'm on Angular 7). I'm using angular-cli to serve the app, which is using webpack, but which (maybe?) isn't supplying these node libraries. Would love to be able to use this, definitely think it could use some documentation for getting it to run in a browser.

@ChristianMurphy
Copy link
Member

Folks, for questions with browser usage please use Spectrum.
https://spectrum.chat/unified

@unifiedjs unifiedjs locked as resolved and limited conversation to collaborators Jun 12, 2019
@wooorm wooorm added the 🙋 no/question This does not need any changes label Aug 10, 2019
@wooorm wooorm changed the title Browser Support? Webpack support Aug 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🙋 no/question This does not need any changes
Development

No branches or pull requests

5 participants