material-ui-pickers icon indicating copy to clipboard operation
material-ui-pickers copied to clipboard

Bad export causing errors for SSR

Open danieljuhl opened this issue 8 years ago • 10 comments

Environment

Tech Version
material-ui-pickers v2.0.0
material-ui
React 16.6.1
Browser node 10/server
Peer library

Steps to reproduce

  1. Create project and import material-ui-pickers
  2. 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 avatar Nov 07 '18 09:11 danieljuhl

@danieljuhl Where do you import components from?

TrySound avatar Nov 07 '18 09:11 TrySound

/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'

TrySound avatar Nov 07 '18 09:11 TrySound

О.о

dmtrKovalenko avatar Nov 07 '18 09:11 dmtrKovalenko

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.

danieljuhl avatar Nov 07 '18 09:11 danieljuhl

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.

danieljuhl avatar Nov 07 '18 09:11 danieljuhl

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.

danieljuhl avatar Nov 07 '18 09:11 danieljuhl

I will fix cjs build ASAP

dmtrKovalenko avatar Nov 07 '18 11:11 dmtrKovalenko

For me import MuiPickersUtilsProvider from 'material-ui-pickers/MuiPickersUtilsProvider'; works on 2.0.0.

victorrodrigues avatar Nov 07 '18 18:11 victorrodrigues

@victorrodrigues on the server? or through webpack (or other bundlers) using babel? The issue is only on the server/node.

danieljuhl avatar Nov 07 '18 20:11 danieljuhl

@danieljuhl oh! I'm sorry. I'm using webpack, not on the server.

victorrodrigues avatar Nov 07 '18 21:11 victorrodrigues