Unexpected token (4003:69) mobx.module.js
Getting error (commonjs plugin) SyntaxError: Unexpected token (4003:69) in /node_modules/mobx/lib/mobx.module.js when using mobx and rollup-plugin-commonjs
rollup-plugin-commonjs is trying to parse string in mobx code ('process.env.NODE_ENV')
Thanks for this issue. It seems that the CommonJS wrongly interprets this file as CommonJS even though it is quite obviously an ES module, which is definitely a bug.
As a workaround until this is fixed, you might try the exclude option:
commonJs({exclude: ['node_modules/mobx/lib/mobx.module.js']})
I had the same issue after i started using the rollup-plugin-replace to replace all occurrences of process.env.NODE_ENV in the code with either 'development' or 'production'
However, mobx had a file the following line:
console.warn(
"[mobx] you are running a minified build, but 'process.env.NODE_ENV' was not set to 'production' in your bundler. This results in an unnecessarily large and slow bundle");
Note the part: 'process.env.NODE_ENV' (incl. single quotes). When the replace happens, this resulted in ''development'' (with TWO single quotes before and after)
This causes the unexpected token error.
I believe they have fixed it in mobx 5.6.0 using two backtick characters to wrap the line.
console.warn(
// Template literal(backtick) is used for fix issue with rollup-plugin-commonjs https://github.com/rollup/rollup-plugin-commonjs/issues/344
`[mobx] you are running a minified build, but 'process.env.NODE_ENV' was not set to 'production' in your bundler. This results in an unnecessarily large and slow bundle`);
For some reason, mobx 5.9.4 has the same problem. :(
I experienced the same thing - mobx 5.9.4 appears to use double quotes again in mobx.module.js for some reason:

EDIT: You can probably just use mobx.es6.js instead (it retains the back ticks):
import alias from 'rollup-plugin-alias';
import path from 'path';
export default {
plugins: [
alias({
mobx: path.join(__dirname, 'node_modules/mobx/lib/mobx.es6.js')
}),
// The rest of your plugins...
],
// The rest of your config...
}
Hey folks (this is a canned reply, but we mean it!). Thanks to everyone who participated in this issue. We're getting ready to move this plugin to a new home at https://github.com/rollup/plugins, and we have to do some spring cleaning of the issues to make that happen. We're going to close this one, but it doesn't mean that it's not still valid. We've got some time yet before the move while we resolve pending Pull Requests, so if this issue is still relevant, please @ me and I'll make sure it gets transferred to the new repo. :beer: