Type error: Type '(string | (string | null)[] | null)[]' is not assignable to type '(string | string[])[]'.
See original GitHub issueDescribe the bug When building with webpack 5 and Nextjs 10.2.0 with ethers 5.1.4, I get the following error:
info - Using webpack 5. Reason: no custom webpack configuration in next.config.js https://nextjs.org/docs/messages/webpack5
Failed to compile.
./node_modules/@ethersproject/providers/src.ts/base-provider.ts:68:5
Type error: Type '(string | (string | null)[] | null)[]' is not assignable to type '(string | string[])[]'.
Type 'string | (string | null)[] | null' is not assignable to type 'string | string[]'.
Type 'null' is not assignable to type 'string | string[]'.
66 | if (data === "") { return [ ]; }
67 |
> 68 | return data.split(/&/g).map((topic) => {
| ^
69 | if (topic === "") { return [ ]; }
70 |
71 | const comps = topic.split("|").map((topic) => {
error Command failed with exit code 1.
Reproduction steps
Run next build on my project
Environment: Running via cli on the following:
Node 14.16.0
Arch linux
webpack 5 enabled
Nextjs 10.2.0
ethers 5.1.4
@typechain/ethers-v5 6.0.5
typechain 4.0.3
This is my tsconfig.json
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
Search Terms webpack 5 nextjs ethers
Issue Analytics
- State:
- Created 2 years ago
- Comments:17 (6 by maintainers)
Top Results From Across the Web
Argument of type 'string | null' is not assignable to parameter of ...
As the error says, localStorage.getItem() can return either a string or null . JSON.parse() requires a string, so you should test the result ......
Read more >Type 'string or null' is not assignable to type string (TS)
The "Type 'string | null' is not assignable to type string" error occurs when a possibly null value is assigned to something that...
Read more >null' is not assignable to type 'string' while working with PCF
While working with PCF you might get the below error. Type 'string | null' is not assignable to type 'string'. Solution.
Read more >Angular | null' is not assignable to parameter of type 'string'
Fix for Angular / TypeScript error when passing a possibly null value to a function that accepts a string.
Read more >Type 'null' is not assignable to type 'string | void' · Issue #8322 ...
Is the documentation still correct? It looks like we cannot assign null to void , so is void the same as undefined ?...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@esemeniuc I had this issue and it ended up that I was importing from @ethersproject/providers/src.ts instead of ethers or @ethersproject/providers. In my case I was typing the JsonRpcProvider.
(Updated thanks to @ricmoo )
Causes Type issues
Works
Also Works
@zemse I ran
rm -rf node_modules yarn.lock && yarn. This is the output: