Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attempted import error: 'path-to-regexp' does not contain a default export (imported as 'pathToRegexp')

Failed to compile the react-router. This happend after installing path-to-regexp

./node_modules/react-router/esm/react-router.js

Attempted import error: 'path-to-regexp' does not contain a default export (imported as 'pathToRegexp').

This error occurred during the build time and cannot be dismissed.

like image 997
Visual LK Avatar asked Jan 06 '20 21:01

Visual LK


2 Answers

For me, this occurred as my path-to-regex had been updated to newer version.

I solved this by simply reverting back to the old version of path-to-regex.To do that simply run this: npm i [email protected] --save

like image 76
Alim Manjiyani Avatar answered Sep 28 '22 05:09

Alim Manjiyani


Instead of downgrading to an old version, just change the way you import: from:

import pathToRegexp from 'path-to-regexp';

to

import { pathToRegexp } from 'path-to-regexp';
like image 23
LoopDuplicate Avatar answered Sep 28 '22 03:09

LoopDuplicate