Closed bladx closed 3 years ago
Can you please double check your yarn.lock file to ensure there are no duplicates of the react-admin related packages?
Sorry I should have been more precise in my previous message. The very first steps of Steps to reproduce are:
node_modules
folder and yarn.lock
fileyarn install
commandyarn build
commandThe error you pasted appears in a file and at a line that wasn't changed over the past 2 years. I believe the problems appears now not because 3.12 changed the source, but because your TypeScript version (and options) have changed.
Which version of TypeScript are you using?
Oh ok, that's weird as I didn't updated my TypeScript version and it did work before.
I did not changed my tsconfig.json
file neither.
So the TypeScript version I'm using is, as I shared in my package.jon
file: 4.1.3
I don't know if this may help you but here is the list of upgrade I did: ("package-name" : "v1" => "v2" where v1 is before the issue and V2 after) "@testing-library/jest-dom": "^5.11.8" => "^5.11.9" "@testing-library/user-event": "^12.6.0" => "^12.6.2" "ra-data-json-server": "^3.11.2" => "^3.12.0" "ra-i18n-polyglot": "^3.12.0""^3.11.2" => "^3.12.0" "ra-input-rich-text": "^3.10.1" => "^3.12.0" "ra-language-english": "^3.11.2" => "^3.12.0" "ra-language-french": "^3.11.2" => "^3.12.0" "react-admin": "^3.11.2" => "^3.12.0" "web-vitals": "^1.0.1" => "^1.1.0" "@types/lodash": "^4.14.167" => "^4.14.168" "@types/node": "^14.14.20" => "^14.14.22" "@types/react-redux": "^7.1.15" => "^7.1.16"
I've upgraded to TypeScript 4.1.3, and I can compile the project without problem.
One think I don't understand is why your react-script command parses the typescript files of the ra-core module. The published modules are in JS.
Sorry but I don't know how to answer that actually.
My react-scripts
dependancy version did not changed.
So I agree that's weird but I do not get why we both have a different behaviour.
I attached the ra-core
folder module I got from yarn install
command if that might help you.
ra-core.zip
Thank you very much for the help by the way, I really appreciate.
I'm sorry but we don't do troubleshooting via GitHub issues, so we won't look at your archive.
I need a minimal way to reproduce your issue. If you can show us a simple CRA project with react-admin 3.12 that doesn't compile, we'll investigate further.
Also, I believe you have a stricter TypeScript configuration than we have. This should explain the errors. Turning off strickNullChecks
in your tsconfig.json
may fix the problem.
Thank you, I tried adding this option but then I got another TS error, still for ra-core
module.
I repeated by deactivating another option, but again a third error so I guess this is not the solution.
Anyway, as you suggested I recreated a project from scratch and added only the minimal code to reproduce.
It appears that this issue seems to come from a custom data provider based on ra-data-json-server
.
So all I did is:
yarn create react-app test-admin --template typescript
cd test-admin/
yarn add react-admin ra-data-json-server prop-types query-string
Then create my data-provider.ts:
import { stringify } from "query-string";
import jsonServerProvider from "ra-data-json-server";
import {
GetListParams,
GetListResult,
Record,
} from "ra-core/src/types";
const apiUrl = process.env.REACT_APP_SERVER_HOST || "";
const httpClient = (
url: string,
options: any = {}
): Promise<{
status: number;
headers: Headers;
body: string;
json: any;
}> => {
if (!options.headers) {
options.headers = new Headers({ Accept: "application/json" });
}
const authToken = `Bearer ${localStorage.getItem("accessToken")}`;
options.headers.set("Authorization", authToken);
return fetchUtils.fetchJson(url, options);
};
const dataProvider = jsonServerProvider(apiUrl, httpClient);
const customDataProvider = {
...dataProvider,
// Customizes the list options and filters query params sent to the server
getList: <RecordType extends Record = Record>(
resource: string,
params: GetListParams
): Promise<GetListResult<RecordType>> => {
const { page, perPage } = params.pagination;
const { field, order } = params.sort;
const query: any = {
page,
perPage,
sortField: field,
sortOrder: order,
};
if (params.filter) {
for (const [key, value] of Object.entries(params.filter)) {
query[`filters[${key}]`] = value;
}
}
const url = `${apiUrl}/${resource}?${stringify(query)}`;
return httpClient(url).then(({ json }) => json);
},
};
export default customDataProvider;
Then edit App.tsx:
import './App.css';
import { Admin } from "react-admin";
import customDataProvider from "./data-provider";
function App() {
return (
<Admin
dataProvider={customDataProvider} />
);
}
export default App;
Then run yarn build
command
Would you like me to edit the issue name or even to close this one and re-create another issue with a better name and only the last message as description?
No, we just need to take the time to try and reproduce the bug as you described.
I do not know if this can help you but I just figured out that running yarn tsc -noEmit
command from the same very simple repo throw 344 errors, all from ra-core
module.
I did not change anything between my last message describing all the steps I did and this command.
And I did not have this issue with ra-core
version: 3.11.2
(but did with 3.12.0
version).
I managed to find the issue myself.
For some reasons I was trying to import types from ra-core/src/types
instead of react-admin
.
Replacing this import source solved my case so I close this ticket.
Sorry for the inconvenience.
Also, I believe you have a stricter TypeScript configuration than we have. This should explain the errors. Turning off
strickNullChecks
in yourtsconfig.json
may fix the problem.
Maybe this should appear in docs as we were having lots of warnings, I was able to remove them (and see real errors) by turning of strickNullChecks. Thanks btw
What you were expecting: I expect my project to build.
What happened instead: I got an error while my
yarn build
command fails.Steps to reproduce: Update the version of
ra-core
module to 3.12.0. (In my case I upgrade to latest version for modules:ra-data-json-server
,ra-i18n-polyglot
,ra-input-rich-text
,ra-language-english
,ra-language-french
andreact-admin
Then run theyarn build
command.Related code:
Other information: Here is my
package.json
file:Environment