slash icon indicating copy to clipboard operation
slash copied to clipboard

[BUG]: @toss/date cannot be imported properly

Open C17AN opened this issue 3 years ago • 0 comments

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.
image

Expected behavior

@toss/date should be available without any tweak, but this package cannot be imported as expected.

To Reproduce

  1. install @toss/date
  2. Use any utils from @toss/date
  3. 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

C17AN avatar Oct 15 '22 18:10 C17AN