Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createContext invalid export with .mjs file #7

Open
ajhenry opened this issue Jun 18, 2019 · 20 comments
Open

createContext invalid export with .mjs file #7

ajhenry opened this issue Jun 18, 2019 · 20 comments

Comments

@ajhenry
Copy link

ajhenry commented Jun 18, 2019

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?

@forabi
Copy link
Contributor

forabi commented Jun 19, 2019

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

@ajhenry
Copy link
Author

ajhenry commented Jun 19, 2019

@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

@forabi
Copy link
Contributor

forabi commented Jun 19, 2019 via email

forabi added a commit that referenced this issue Jun 29, 2019
@forabi
Copy link
Contributor

forabi commented Jun 29, 2019

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

@ajhenry
Copy link
Author

ajhenry commented Jun 29, 2019

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

@forabi
Copy link
Contributor

forabi commented Jun 30, 2019

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 🤔

@ajhenry
Copy link
Author

ajhenry commented Jul 1, 2019

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 ajhenry closed this as completed Jul 1, 2019
forabi added a commit that referenced this issue Jul 4, 2019
@EthanHolman
Copy link

@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.

@ajhenry
Copy link
Author

ajhenry commented Nov 26, 2019

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

@forabi
Copy link
Contributor

forabi commented Nov 26, 2019

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

@igorclaudino
Copy link

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?

@alyshahudson
Copy link

I'm having the same error!

@chrislondon
Copy link

Same error here.

@benoit-ctrl
Copy link

Hello, I have find a fix to this problem thanks to reactioncommerce/reaction-component-library#399 (comment).
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

@niyodusengaclement
Copy link

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

@benoit-ctrl
Copy link

benoit-ctrl commented Nov 4, 2020

@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.

@devcosta
Copy link

devcosta commented Nov 4, 2020

image

Ty @benoit-ctrl, you solution works

It was necessary to set manually the height of element

@niyodusengaclement
Copy link

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

@benoit-ctrl
Copy link

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.

@niyodusengaclement
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants