Error when loading date-fns dependency: Cannot read property 'default' of null
See original GitHub issueDescribe the bug
I’m using Svelte Kit and Kit uses Vite. After the first start of the project, and the first time visiting the localhost:3000, in the kit console it throws the below log. After second start of project, it doesn’t throw any error. Also, if you delete .svelte
and node_modules
folders, then start project, it will again throw errors.
Reproduction
I have a public repo for this:
https://github.com/kahverengi001/vite-reproduction-bug-date-fns
System Info
Output of npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers
:
❯ npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers
System:
OS: Linux 5.10 Arch Linux
CPU: (8) x64 Intel(R) Core(TM) i7-4720HQ CPU @ 2.60GHz
Memory: 280.51 MB / 15.54 GB
Container: Yes
Shell: 5.8 - /bin/zsh
Binaries:
Node: 15.14.0 - /usr/bin/node
Yarn: 1.22.10 - /usr/bin/yarn
npm: 7.10.0 - /usr/bin/npm
Browsers:
Chromium: 90.0.4430.72
Firefox: 87.0
npmPackages:
vite: ^2.1.0 => 2.1.5
Used package manager: npm/yarn
Logs
❯ yarn dev
yarn run v1.22.10
$ svelte-kit dev
SvelteKit v1.0.0-next.83
local: http://localhost:3000
network: not exposed
network: not exposed
network: not exposed
network: not exposed
Use --host to expose server to other devices on this network
11:24:33 AM [vite] new dependencies found: date-fns, updating...
11:24:34 AM [vite] ✨ dependencies updated, reloading page...
Cannot read property 'default' of null
TypeError: Cannot read property 'default' of null
at eval (/src/lib/Header/index.svelte:24:223)
at Object.$$render (/home/kahverengi/vite-reproduction-bug-date-fns/node_modules/svelte/internal/index.js:1369:22)
at eval (/home/kahverengi/vite-reproduction-bug-date-fns/src/routes/$layout.svelte:20:94)
at Object.$$render (/home/kahverengi/vite-reproduction-bug-date-fns/node_modules/svelte/internal/index.js:1369:22)
at eval (//home/kahverengi/vite-reproduction-bug-date-fns/.svelte/dev/generated/root.svelte:55:122)
at $$render (/home/kahverengi/vite-reproduction-bug-date-fns/node_modules/svelte/internal/index.js:1369:22)
at Object.render (/home/kahverengi/vite-reproduction-bug-date-fns/node_modules/svelte/internal/index.js:1377:26)
at render_response (file:///home/kahverengi/vite-reproduction-bug-date-fns/node_modules/@sveltejs/kit/dist/ssr.js:364:28)
at async respond (file:///home/kahverengi/vite-reproduction-bug-date-fns/node_modules/@sveltejs/kit/dist/ssr.js:1110:10)
at async render_page (file:///home/kahverengi/vite-reproduction-bug-date-fns/node_modules/@sveltejs/kit/dist/ssr.js:1154:20)
Additional Context There is also a tracking current issue in Svelte Kit repo: https://github.com/sveltejs/kit/issues/1111
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Module not found: Can't resolve '@date-io/date-fns'
In my code, I have used "import DateFnsUtils from "@date-io/date-fns/build/date-fns-utils" , which caused "Module not found: Error: Can't ...
Read more >npm cannot read properties of null (reading 'matches') - You.com ...
I run npm install canvas png-js date-fns axios crypto-js ts-md5 tslib @types/node dotenv ... Cannot read property 'match' of undefined error handling.
Read more >modern JavaScript date utility library - date-fns
date-fns provides the most comprehensive yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js.
Read more >react-datepicker - npm
If you need to use a locale other than the default en-US, you'll also need to import that into your project from date-fns...
Read more >Datepicker - Angular Material
A datepicker is composed of a text input and a calendar pop-up, connected via the matDatepicker property on the text input.
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 FreeTop 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
Top GitHub Comments
I am also using
date-fns
in my SvelteKit project, try to move the library todevDependencies
inpackage.json
Should fix your problem 😉removing this part from authors reproduction in svelte.config.cjs makes date-fns work
npmPackages: @sveltejs/adapter-node: next => 1.0.0-next.16 @sveltejs/kit: next => 1.0.0-next.83 vite: ^2.1.0 => 2.1.5