React-markdown: process.cwd is not a function when running example

Created on 26 Jun 2018  路  6Comments  路  Source: remarkjs/react-markdown

Hello,
Im trying to run the example, but Im getting the error from vfile lib. The example looks pretty straight forward so I didn't expect any issues. I wonder what I may possibly do incorrect because running process.cwd() (core.js:47) in browser sounds a bit unnatural.

TypeError: Object(...).cwd is not a function
    at new VFile (core.js:47)
    at VFile (core.js:41)
    at Function.parse (index.js:269)
    at ReactMarkdown (react-markdown.js:31)
    at ProxyFacade (react-hot-loader.development.js:617)
    at mountIndeterminateComponent (react-dom.development.js:8574)
    at beginWork (react-dom.development.js:8978)
    at performUnitOfWork (react-dom.development.js:11814)
    at workLoop (react-dom.development.js:11843)
    at renderRoot (react-dom.development.js:11874)

appreciate all hints and help,
cheers

Most helpful comment

@anicholson thank you for the input, I solved it too. In my case I was using webpack.DefinePlugin to pass env to a node. vfile's process was replaced by hash with envs that doesn't contain cwd function - thats why I got error Object(...).cwd is not a function. Initially I added noop cwd, but broke some Uglify functionalities. So my final solution is to look for whole 'process.env'.

// BAD (initial issue)
new webpack.DefinePlugin({
  process: {
    env: {
      APP_ENV: '...',
    },
  },
})


// BAD (solves the issue but breaks other things)
new webpack.DefinePlugin({
  process: {
    cwd: () => {},
    env: {
      APP_ENV: '...',
    },
  },
})


// GOOD
new webpack.DefinePlugin({
  'process.env': {
    APP_ENV: '...',
  },
})

All 6 comments

I'm seeing this too, with versions: react-markdown@ 3.2.2, unified @ 6.2.0 and vfile @ 2.3.0

I'm guessing it's caused by this: https://github.com/vfile/vfile/pull/28

@kubenstein I solved this issue by asking Webpack to mock process for me.

@anicholson thank you for the input, I solved it too. In my case I was using webpack.DefinePlugin to pass env to a node. vfile's process was replaced by hash with envs that doesn't contain cwd function - thats why I got error Object(...).cwd is not a function. Initially I added noop cwd, but broke some Uglify functionalities. So my final solution is to look for whole 'process.env'.

// BAD (initial issue)
new webpack.DefinePlugin({
  process: {
    env: {
      APP_ENV: '...',
    },
  },
})


// BAD (solves the issue but breaks other things)
new webpack.DefinePlugin({
  process: {
    cwd: () => {},
    env: {
      APP_ENV: '...',
    },
  },
})


// GOOD
new webpack.DefinePlugin({
  'process.env': {
    APP_ENV: '...',
  },
})

Always dumping the symptoms... what has vfile, path and process to do with a REACT markdown renderer,

For anyone stumbling in here now: We ran in to this issue on v4.3.1 when we upgraded webpack to v5.9 from v4.x.

By upgrading from 4.3.1 to 5.0.3 our issues went away.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

IonicaBizau picture IonicaBizau  路  4Comments

pcvandamcb picture pcvandamcb  路  3Comments

ScarellaDev picture ScarellaDev  路  3Comments

joelin109 picture joelin109  路  3Comments

AlexLerman picture AlexLerman  路  3Comments