Bad export causing errors for SSR
Environment
| Tech | Version |
|---|---|
| material-ui-pickers | v2.0.0 |
| material-ui | |
| React | 16.6.1 |
| Browser | node 10/server |
| Peer library |
Steps to reproduce
- Create project and import material-ui-pickers
- Start the project on the server (eg. with babel-node) 3.
Expected behavior
The app/project to start
Actual behavior
It crashes, due to the use of import/export in the npm package
node_modules/material-ui-pickers/DatePicker/index.js:1
(function (exports, require, module, __filename, __dirname) { export { default } from './DatePickerModal';
^^^^^^
SyntaxError: Unexpected token export
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
Live example
@danieljuhl Where do you import components from?
/cc @dmtrKovalenko Seems like you don't transpile modules to cjs in this release. @danieljuhl Try to import from package instead of path.
import {} from 'material-ui-pickers'
О.о
This happens when importing the UtilsProvider.
I've tried import { MuiPickersUtilsProvider } from 'material-ui-pickers'; and import MuiPickersUtilsProvider from 'material-ui-pickers/MuiPickersUtilsProvider';. I've even tried import MuiPickers from 'material-ui-pickers';. If using webpack or other bundlers, they will handle the ESM import/export, but on the server babel is per default disabled for node_modules.
Ignore the above comment.. import MuiPickersUtilsProvider from 'material-ui-pickers/MuiPickersUtilsProvider'; failed, but import { MuiPickersUtilsProvider } from 'material-ui-pickers'; works. I had another direct import. After importing everything with import {} from 'material-ui-pickers' it works.
But I haven't tested what the impact on final bundle size will be. Previously it was important to use direct import of component, to reduce the bundle size.
I will fix cjs build ASAP
For me import MuiPickersUtilsProvider from 'material-ui-pickers/MuiPickersUtilsProvider'; works on 2.0.0.
@victorrodrigues on the server? or through webpack (or other bundlers) using babel? The issue is only on the server/node.
@danieljuhl oh! I'm sorry. I'm using webpack, not on the server.