marmelab / react-admin

A frontend Framework for single-page applications on top of REST/GraphQL APIs, using TypeScript, React and Material Design
http://marmelab.com/react-admin
MIT License
24.84k stars 5.23k forks source link

Install react-admin 3.10.1 but get ra-core latest 3.13.0 #5979

Closed hieusmiths closed 3 years ago

hieusmiths commented 3 years ago

What you were expecting: Has no exported member 'TestContext'. Did you mean 'ListContext' What happened instead:

Steps to reproduce:

Package.json "react-admin": "3.10.1"

Related code:

import { TestContext } from "react-admin";

Other information:

Environment

fzaninotto commented 3 years ago

Hi, and thanks for your issue. I don't understand where your bug occurs. If you're importing TestContext in your code, then the 3.13 release notes explain what you need to do.

If the bug occurs without you importing TestContext manually, can you please link to a CodeSandbox reproducing it?

fzaninotto commented 3 years ago

Also, you can lock the 'ra-core' version to 3.10.1 using resolutions in your packages.json to avoid the problem.

djhi commented 3 years ago

You probably don't need resolutions and just add a dependency to the version of ra-core you want in your project

danjebs commented 3 years ago

Not a complete reproduction, but hopefully more information to help clarify the issue.

I had a working react-admin a week ago, took a holiday and came back to find Docker spinning up the admin (on dev):

  1. Initially with all resources using their i18n IDs instead of names, and nothing loading
  2. After re-building, receiving the error ./node_modules/ra-ui-materialui/esm/input/ReferenceArrayInput.js Attempted import error: 'ReferenceArrayInputContextProvider' is not exported from 'ra-core'.

This was the package.json file:

{
  "name": "morpheus",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev -p 5000",
    "build": "next build",
    "start": "next start -p 5000"
  },
  "dependencies": {
    "@apollo/client": "^3.0.2",
    "@ckeditor/ckeditor5-react": "^3.0.0",
    "@rails/activestorage": "^6.0.3-2",
    "graphql": "^15.3.0",
    "lodash": "^4.17.16",
    "next": "10.0.1",
    "query-string": "^6.13.1",
    "ra-core": "3.12.5",
    "ra-data-graphql": "^3.6.1",
    "ra-data-graphql-simple": "^3.6.1",
    "ra-data-json-server": "^3.7.0",
    "react": "^16.13.1",
    "react-admin": "3.10.4",
    "react-beautiful-dnd": "^13.0.0",
    "react-dom": "^16.13.1",
    "trix": "^1.2.4",
    "util": "^0.12.3"
  }
}

I then bumped both react-admin and ra-core to 3.13.1 and re-built the project and it works again.

So issue solved - but it's happened a few times that, without changing anything in package.json, the admin breaks. Previously when deploying a working dev project to stage (stage broke, then dev broke afterwards when I re-built dev). Fortunately not yet when deploying to prod.

I realise that the description above is not a specific issue with a specific version. And perhaps it's also frustrating for you when people who aren't so familiar with NPM versioning settings are reporting what seems like a basic "ask Stack Overflow" question. But it's a friction point for myself (and presumably others) that the project can fall over when re-building from an unchanged package.json, even with locked version numbers. And that doesn't happen with any other packages that I use.

I hope I've explained that clearly. It's not necessarily a bug with the package, but (I guess) an issue that arises from having a fast-moving project where users aren't using the package.json file as you intend.

It could just be that the installation documentation can have a section about versioning and that would help us understand the correct way to set up our package.json files.

fzaninotto commented 3 years ago

The problem is that the dependencies with internal packages (ra-core, ra-ui-materialui) in react-admin use ^ instead of ~:

    "dependencies": {
        "@material-ui/core": "^4.11.2",
        "@material-ui/icons": "^4.11.2",
        "@material-ui/styles": "^4.11.2",
        "connected-react-router": "^6.5.2",
        "final-form": "^4.20.0",
        "final-form-arrays": "^3.0.1",
        "ra-core": "^3.13.1",
        "ra-i18n-polyglot": "^3.13.1",
        "ra-language-english": "^3.13.1",
        "ra-ui-materialui": "^3.13.1",
        "react-final-form": "^6.3.3",
        "react-final-form-arrays": "^3.1.1",
        "react-redux": "^7.1.0",
        "react-router": "^5.1.0",
        "react-router-dom": "^5.1.0",
        "redux": "^3.7.2 || ^4.0.3",
        "redux-saga": "^1.0.0"
    }

This is not something we can fix for past version, but we should definitely switch to ~ ASAP.

Marking this as a bug.

danjebs commented 3 years ago

Thanks for the quick response guys 🎉💃❤️