Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixing 'define' is not defined no-undef in react create app third party imports

i have imported momentjs in my react app, after importing react create app is throwing following error restricting the build

./src/shared_components/quiz-player/node_modules/moment/moment.js
Line 9: 'define' is not defined no-undef

when i investigate the issue it is thrown from following line

typeof define === 'function' && define.amd ? define(factory) :
global.moment = factory()

this is due to amd module definition and since this is a third party library i have no option of resolving the issue, is there any thing that can be done to tell the webpack config to expect amd module definition or some other fix for this?

like image 632
Rangana Sampath Avatar asked Mar 01 '18 07:03

Rangana Sampath


2 Answers

...

/* eslint no-undef: */
typeof define === 'function' && define.amd 
  ? define(factory) 
  : global.moment = factory();

...

more see https://eslint.org/docs/2.0.0/rules/no-undef

like image 86
Liu Lei Avatar answered Oct 10 '22 19:10

Liu Lei


You can add the following to the tsconfig.json file at the root level of your project folder:

{"skipLibCheck": true,}

This should solve the error.

like image 33
David Tse Avatar answered Oct 10 '22 19:10

David Tse