react-week-scheduler icon indicating copy to clipboard operation
react-week-scheduler copied to clipboard

createContext invalid export with .mjs file

Open ajhenry opened this issue 5 years ago • 20 comments

We are looking at using this library for our project and it looks really promising, especially with the fluid drag to enlarge.

However, when I try to install the package into a JS-only React project, I am met with the following error:

Failed to compile.

./node_modules/@remotelock/react-week-scheduler/index.mjs
Can't import the named export 'createContext' from non EcmaScript module (only default export is available)

I copied the code from the sample in the Readme to produce this error

~~This seems to be an issue related to breaking changes in webpack and how it treats .mjs files as listed here~~

~~And a dirty fix appears to be something along the following, as discussed here~~

{
  type: 'javascript/auto',
  test: /\.mjs$/,
  use: []
}

Edit

This appears to be an issue with create-react-app and the default webpack config it's using, as it will not support .mjs extensions until jest does.

So is there any plan to support projects bootstrapped with create-react-app without ejecting?

ajhenry avatar Jun 18 '19 14:06 ajhenry

Hey @AJHenry, thanks for the interest in this package. Any suggestions on how to fix this? I can look into it this weekend!

forabi avatar Jun 19 '19 20:06 forabi

@forabi Thanks for getting back to me.

Honestly, I have no idea what is causing this issue, as I am unable to reproduce in codesandbox even though my dependency versions all match

Here is what I am met with in my console when I try to import TimeGridScheduler in a JS-only environment bootstrapped with cra.

Screen Shot 2019-06-19 at 5 12 19 PM

After building and linking locally, changing the package.json module extension from .mjs to .js fixes the import error, but then introduces a hook error that I'm not quite sure what is causing it.

Screen Shot 2019-06-19 at 5 23 01 PM

Unfortunately, I've never run into this problem with React and don't know where to go from here

ajhenry avatar Jun 19 '19 21:06 ajhenry

These are good first hints. Thanks! Like I said, will take a stab at fixing this on weekend.

On Thu, Jun 20, 2019, 12:24 AM Andrew Henry [email protected] wrote:

@forabi https://github.com/forabi Thanks for getting back to me.

Honestly, I have no idea what is causing this issue, as I am unable to reproduce in codesandbox https://codesandbox.io/s/competent-nightingale-qc9sf even though my dependency versions all match

Here is what I am met with in my console when I try to import TimeGridScheduler in a JS-only environment bootstrapped with cra.

[image: Screen Shot 2019-06-19 at 5 12 19 PM] https://user-images.githubusercontent.com/24923406/59800770-73243780-92b5-11e9-8006-9eed493259be.png

After building and linking locally, changing the package.json module extension from .mjs to .js fixes the import error, but then introduces a hook error that I'm not quite sure what is causing it.

[image: Screen Shot 2019-06-19 at 5 23 01 PM] https://user-images.githubusercontent.com/24923406/59802400-ff832a00-92b6-11e9-9833-d74eb4fb292c.png

Unfortunately, I've never run into this problem with React and don't know where to go from here

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/remotelock/react-week-scheduler/issues/7?email_source=notifications&email_token=AAHXIGK2DRGFTKGDR3OMRDDP3KP2VA5CNFSM4HZAN6B2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYDKOEI#issuecomment-503752465, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHXIGPLZV3GRQECTMSIP5DP3KP2VANCNFSM4HZAN6BQ .

forabi avatar Jun 19 '19 21:06 forabi

@AJHenry Can you test @remotelock/react-week-scheduler@next and see if it's working for you?

forabi avatar Jun 29 '19 10:06 forabi

Same issue with the non EcmaScript module, I'll try building locally and report back

ajhenry avatar Jun 29 '19 22:06 ajhenry

That's weird. I went over all the imports in the screenshot above and used namespace imports instead of defaults + named imports. I don't see why this wouldn't work 🤔

forabi avatar Jun 30 '19 11:06 forabi

Not too sure either, but thank you for all your effort!

I'm going to close this issue as I have a growing suspicion another package in my dependency tree is causing this. For when I create a new project with the same dependency versions, it does not give me any errors.

Thanks again for all your help

ajhenry avatar Jul 01 '19 13:07 ajhenry

@AJHenry did you ever discover which package was causing the issue for you? I am encountering this same problem and have yet to discover a solution.

EthanHolman avatar Nov 25 '19 19:11 EthanHolman

@EthanHolman Unfortunately I did not. I had to switch to another package that didn't have this issue

ajhenry avatar Nov 26 '19 16:11 ajhenry

@AJHenry @EthanHolman Can you test the suggested change to webpack config in #14 ?

forabi avatar Nov 26 '19 17:11 forabi

Hello. I am using React version 16.13.0 and I am having this same issue. The project was created using the create-react-app. Any suggestion?

igorclaudino avatar Mar 10 '20 16:03 igorclaudino

I'm having the same error!

alyshahudson avatar Apr 25 '20 03:04 alyshahudson

Same error here.

chrislondon avatar Jul 11 '20 03:07 chrislondon

Hello, I have find a fix to this problem thanks to https://github.com/reactioncommerce/reaction-component-library/issues/399#issuecomment-518823748. You can override CRA webpack config without ejecting and solve the problem like this :

  1. Install customize-cra and react-app-rewired as dev dependencies :

npm install -D customize-cra react-app-rewired

  1. Then create a file named config-overrides.js in the same folder as package.json and copy this configuration :
// config-overrides.js
const { override } = require("customize-cra");

const supportMjs = () => (webpackConfig) => {
    webpackConfig.module.rules.push({
        test: /\.mjs$/,
        include: /node_modules/,
        type: "javascript/auto",
    });
    return webpackConfig;
};

module.exports = override(
    supportMjs()
);
  1. Finally in your package.json file replace the NPM scripts with the rewired version :
"scripts": {
    "start": "react-app-rewired start",
    "build": "react-app-rewired build",
    "test": "react-app-rewired test",
    "eject": "react-scripts eject"
  },

@forabi it might be useful to add this in the README

benoit-ctrl avatar Jul 27 '20 16:07 benoit-ctrl

@benoit-ctrl Thanks for your hint it solved the mentioned error, but unfortunately, it doesn't display anything in the browser

niyodusengaclement avatar Nov 04 '20 19:11 niyodusengaclement

@benoit-ctrl Thanks for your hint it solved the mentioned error, but unfortunately, it doesn't display anything in the browser

@niyodusengaclement Maybe it's rather due to the way you use the scheduler, you could copy and paste some of your code (but nothing sensitive or private) into a codesandbox (https://codesandbox.io/) for testing purposes and if you still have a problem open another ticket with the link to the sandbox. There is a link to a functional codesandbox example in the README.

benoit-ctrl avatar Nov 04 '20 20:11 benoit-ctrl

image

Ty @benoit-ctrl, you solution works

It was necessary to set manually the height of element

devcosta avatar Nov 04 '20 23:11 devcosta

@devcosta I've tried to set height manually but doesn't help too, here is my sandbox (https://codesandbox.io/s/focused-bush-0eem6)

niyodusengaclement avatar Nov 05 '20 07:11 niyodusengaclement

2020-11-05 13_02_34-Window @niyodusengaclement You need to put your style height directly on the TimeGridScheduler tag and not on the parent div.

benoit-ctrl avatar Nov 05 '20 12:11 benoit-ctrl

Thanks, @benoit-ctrl, and others for your support. Now it's working

niyodusengaclement avatar Nov 05 '20 12:11 niyodusengaclement