slash
slash copied to clipboard
[BUG]: @toss/date cannot be imported properly
Package Scope
Package name: @toss/date
Describe the bug
When trying to use utils from @toss/date package, it throws error below.
Module not found: Error: Can't resolve 'date-fns/locale/ko' in '/Users/chanmin/react-test/node_modules/@toss/date/esm'
Did you mean 'index.js'?
BREAKING CHANGE: The request 'date-fns/locale/ko' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
Expected behavior
@toss/date should be available without any tweak, but this package cannot be imported as expected.
To Reproduce
- install
@toss/date - Use any utils from
@toss/date - Run / Build fails.
Possible Solution
Add .js extension on date-fns locale import
AS-IS
// packages/common/date/src/date.ts
// eslint-disable-next-line import/no-duplicates
import { format as _format, isAfter, isBefore, isEqual, isValid } from 'date-fns';
import locale from 'date-fns/locale/ko'; // => This import statement should be changed (to explicitly provide extension)
TO-BE
// eslint-disable-next-line import/no-duplicates
import { format as _format, isAfter, isBefore, isEqual, isValid } from 'date-fns';
import locale from 'date-fns/locale/ko/index.js';
Additional context
Quotation