Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors when updating. Webpack related #792

Open
developdeez opened this issue Feb 4, 2020 · 11 comments
Open

Errors when updating. Webpack related #792

developdeez opened this issue Feb 4, 2020 · 11 comments

Comments

@developdeez
Copy link

I haven't had this error until I updated. What loader do I use with dayjs now?

WARNING in ./node_modules/dayjs/locale/types.d.ts 1:8
Module parse failed: Unexpected token (1:8)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders

declare interface ILocale {
| name: string
| weekdays?: string[]
@ ./node_modules/dayjs/locale lazy ^./.*$ namespace object ./types.d.ts
@ ./src/index.js

@iamkun
Copy link
Owner

iamkun commented Mar 27, 2020

Any reproduction repo, please?

@mariusa
Copy link

mariusa commented Apr 11, 2020

It happens when using

require('dayjs/locale/' + lang)

That is, with a variable.

Example:

vue create hello-world
cd hello-world/
npm install dayjs --save
npm run serve

then change main.js to

import Vue from 'vue'
import App from './App.vue'

Vue.config.productionTip = false

import day from 'dayjs'
let lang = 'ro'
require('dayjs/locale/' + lang)
console.log(day().format())

new Vue({
  render: h => h(App),
}).$mount('#app')

jcbrand added a commit to conversejs/converse.js that referenced this issue Apr 15, 2020
@munkhorgil
Copy link
Contributor

Any update on this? I got this error too when dynamically importing locales.

@iamkun
Copy link
Owner

iamkun commented May 29, 2020

@munkhorgil Any reproduction repo, please?

@munkhorgil
Copy link
Contributor

munkhorgil commented May 29, 2020

@munkhorgil Any reproduction repo, please?

https://github.com/erxes/erxes in widget we use the dayjs

@iamkun
Copy link
Owner

iamkun commented May 29, 2020

thanks, @munkhorgil, nice project.

However, it is hard for me to debug this issue in this huge repo. Can you please provide an issue reproduction repo containing this issue only, if you have time.

Cheers

@munkhorgil
Copy link
Contributor

thanks, @munkhorgil, nice project.

However, it is hard for me to debug this issue in this huge repo. Can you please provide an issue reproduction repo containing this issue only, if you have time.

Cheers

Thanks, in order to reproduce you don’t need to install the whole project.

  1. Clone project
  2. Navigate to widgets folder
  3. cp .env.sample .env
  4. yarn install
  5. yarn dev

Screen Shot 2020-05-29 at 4 28 52 PM

@JounQin
Copy link
Contributor

JounQin commented Jun 6, 2020

@developdeez @mariusa @iamkun I think the key point is require('dayjs/locale/' + lang), webpack will try to package all files under locale folder including .d.ts files, and the workaround is require('dayjs/locale/' + lang + '.js'), I tried @mariusa 's reproduction and it worked.

And @munkhorgil , I didn't find dayjs used in the reproduction project.

@Alexis-Bize
Copy link

Alexis-Bize commented Nov 28, 2020

Had this issue minutes ago and my current workaround (based on my needs) is to dynamically import each lang, based on the specified locale.

type Locale = 'en-US' | 'fr-FR';

export const importDayJSLang = (locale: Locale) => {
	const lang = locale.split('-')[0];

	if (locale === 'en-US')
		return import(`dayjs/locale/en`).then(() => {
			dayjs.locale(lang);
			return lang;
		});
	else if (locale === 'fr-FR')
		return import(`dayjs/locale/fr`).then(() => {
			dayjs.locale(lang);
			return lang;
		});
	else return Promise.resolve(lang);
};

A refactoring is of course possible, but I pasted it as it to give an idea.

@elobuho
Copy link

elobuho commented Dec 2, 2020

@JounQin
Yup,
import(dayjs/locale/${locale}.js).then(() => {

solves the problem. Thank you.

klimeryk added a commit to klimeryk/recalendar.js that referenced this issue Jan 4, 2022
From iamkun/dayjs#792 (comment)

Looks like webpack is trying to package everything, so we need to
explicitly tell it that we want just the JS files.
@duongdam
Copy link

@developdeez @mariusa @iamkun I think the key point is require('dayjs/locale/' + lang), webpack will try to package all files under locale folder including .d.ts files, and the workaround is require('dayjs/locale/' + lang + '.js'), I tried @mariusa 's reproduction and it worked.

And @munkhorgil , I didn't find dayjs used in the reproduction project.

Thanks

afialapis added a commit to afialapis/intre that referenced this issue Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants