Closed NJXZhang closed 4 years ago
It looks like this is a Typescript issue and it's a problem for lots of libs. A quick search turned up the following:
https://github.com/auth0/auth0-spa-js/issues/99 https://github.com/gorangajic/isbot/issues/41 https://github.com/molnarg/js-schema/issues/49 https://github.com/middyjs/middy/issues/203 https://github.com/iamkun/dayjs/issues/475
I'm importing this lib from a non-typescript codebase. I don't know enough TS to debug this but, from what I can gather, it's something to do with how the module system does interop with and will ultimately be resolved through fiddling with the allowSyntheticDefaultImports
and esModuleInterop
flags.
You can see some of the TS module system discussions from way back at 1.5 and a pretty steady stream of issues around ES6 interop like this one in the TS codebase.
Sorry, I should add stacktrace to this to make the report a bit more helpful. It's not clear to me from this whether the problem is my project's ES6 import of date-fns-upgrade
or if it's a Typescript interop issue between date-fns-upgrade
and date-fns
My projectis a Next.js 9 (the latest) project using JavaScript (not Typescript) that compiles using babel-preset-env
for the latest 3 Chrome versions. I've tried the following import formats out of curiosity and they all emit the same error:
import { legacyParse } from '@date-fns/upgrade/v2';
import * as datefnsUpgrade from '@date-fns/upgrade/v2';
const { legacyParse } = datefnsUpgrade
const { legacyParse } = require('@date-fns/upgrade/v2');
const datefnsUpgrade = require('@date-fns/upgrade/v2');
const { legacyParse } = datefnsUpgrade
TypeError: isDate_1.default is not a function
at legacyParse (<project_path>/node_modules/@date-fns/upgrade/v2/legacyParse/index.js:38:23)
at <project_path>/.next/server/static/development/pages/_app.js:2706:71
at index (<project_path>/.next/server/static/development/pages/_app.js:2784:173)
at A (<project_path>/node_modules/lodash/lodash.min.js:9:54)
at An.times (<project_path>/node_modules/lodash/lodash.min.js:124:472)
at l (<project_path>/node_modules/lodash/lodash.min.js:50:137)
at <project_path>/node_modules/lodash/lodash.min.js:49:114
at generateLines (<project_path>/.next/server/static/development/pages/_app.js:2785:147)
at Module../src/redux/modules/order/index.js (<project_path>/.next/server/static/development/pages/_app.js:2802:20)
at __webpack_require__ (<project_path>/.next/server/static/development/pages/_app.js:23:31)
at Module../src/redux/reducers.js (<project_path>/.next/server/static/development/pages/_app.js:3310:73)
at __webpack_require__ (<project_path>/.next/server/static/development/pages/_app.js:23:31)
at Module../src/redux/create-store.js (<project_path>/.next/server/static/development/pages/_app.js:1009:67)
at __webpack_require__ (<project_path>/.next/server/static/development/pages/_app.js:23:31)
at Module../pages/_app.js (<project_path>/.next/server/static/development/pages/_app.js:885:81)
at __webpack_require__ (<project_path>/.next/server/static/development/pages/_app.js:23:31)
Hi! Thank you for reporting this.
We've published date-fns-upgrade@1.0.1
that should solve this issue without using interop.
Let us know if you still have problems.
Thank you so much for the quick fix. It is working now.
When try to follow the example.:
The following error occurs TypeError: isDate_1.default is not a function If I remove
.default
from theif (isDate_1.default(argument)) {
, it will work.