简体   繁体   中英

Material-UI Can't import slider

import Slider from '@material-ui/lab/Slider';

returns an error on build

ERROR in ./src/components/StepSlider/StepSlider-view.jsx
Module not found: Error: Can't resolve '@material-ui/lab/Slider' in 'D:\GIT\...\components\StepSlider'
 @ ./src/components/StepSlider/StepSlider-view.jsx 2:0-45 29:26-32
 @ ./src/components/StepSlider/index.js
 @ ./src/components/plan_option_slider/PlanOptionSlider-view.jsx
 @ ./src/components/plan_option_slider/index.jsx
 @ ./src/features/plans/plans-view.jsx
 @ ./src/features/plans/index.jsx
 @ ./src/App.jsx
 @ ./src/index.jsx

Searching this error tells me to install lab , I'd already done that, but figured I'd give it another chance:

npm install @material-ui/lab

npm WARN bootstrap@4.4.1 requires a peer of popper.js@^1.16.0 but none is installed. You must install peer dependencies yourself.
npm WARN material-ui-pickers@2.2.4 requires a peer of @material-ui/core@^3.2.0 but none is installed. You must install 
peer dependencies yourself.
npm WARN restaurant_project@1.0.0 No description
npm WARN restaurant_project@1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ @material-ui/lab@4.0.0-alpha.40
updated 1 package and audited 12006 packages in 13.041s
found 0 vulnerabilities

I followed this: npm WARN ... requires a peer of ... but none is installed. You must install peer dependencies yourself (I was pretty sure I had all this installed, but figured I'd follow directions)

npm install --save-dev popper.js@^1.16.0

npm WARN deprecated popper.js@1.16.0: Popper changed home, find its new releases at @popperjs/core
npm WARN material-ui-pickers@2.2.4 requires a peer of @material-ui/core@^3.2.0 but none is installed. You must install 
peer dependencies yourself.
npm WARN restaurant_project@1.0.0 No description
npm WARN restaurant_project@1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ popper.js@1.16.0
updated 1 package and audited 12007 packages in 15.415s
found 0 vulnerabilities

npm install --save-dev @material-ui/core@^3.2.0

npm WARN @material-ui/icons@4.5.1 requires a peer of @material-ui/core@^4.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @material-ui/lab@4.0.0-alpha.40 requires a peer of @material-ui/core@^4.9.0 but none is installed. You must install peer dependencies yourself.
npm WARN restaurant_project@1.0.0 No description
npm WARN restaurant_project@1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ @material-ui/core@3.2.0
added 4 packages from 4 contributors, removed 26 packages, updated 5 packages and audited 11946 packages in 25.503s    
found 0 vulnerabilities

This looks worrisome, it seems like the lab is asking for core4.9.0, but okay:

npm install --save-dev @material-ui/core@^4.0.0

npm WARN @material-ui/lab@4.0.0-alpha.40 requires a peer of @material-ui/core@^4.9.0 but none is installed. You must install peer dependencies yourself.
npm WARN material-ui-pickers@2.2.4 requires a peer of @material-ui/core@^3.2.0 but none is installed. You must install 
peer dependencies yourself.
npm WARN restaurant_project@1.0.0 No description
npm WARN restaurant_project@1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ @material-ui/core@4.0.0
added 26 packages from 8 contributors, removed 6 packages, updated 1 package and audited 12027 packages in 14.485s     
found 0 vulnerabilities

So now it's telling me I need @material-ui/core@^3.2.0 again -- great, let me see if I can ignore that (it'll clear out the 4.9.0 I just installed)

npm install --save-dev @material-ui/core@^4.9.0

npm WARN material-ui-pickers@2.2.4 requires a peer of @material-ui/core@^3.2.0 but none is installed. You must install 
peer dependencies yourself.
npm WARN restaurant_project@1.0.0 No description
npm WARN restaurant_project@1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ @material-ui/core@4.9.0
added 5 packages from 4 contributors, removed 3 packages, updated 5 packages and audited 12007 packages in 15.823s     
found 0 vulnerabilities

Alright, let's see if I can build it now.

No dice

ERROR in ./src/components/StepSlider/StepSlider-view.jsx
Module not found: Error: Can't resolve '@material-ui/lab/Slider' in 'D:\GIT\...\src\components\StepSlider'
 @ ./src/components/StepSlider/StepSlider-view.jsx 2:0-45 29:26-32
 @ ./src/components/StepSlider/index.js
 @ ./src/components/plan_option_slider/PlanOptionSlider-view.jsx
 @ ./src/components/plan_option_slider/index.jsx
 @ ./src/features/plans/plans-view.jsx
 @ ./src/features/plans/index.jsx
 @ ./src/App.jsx
 @ ./src/index.jsx

I'll try updating everything:

npm update

npm WARN deprecated popper.js@1.16.1: Popper changed home, find its new releases at @popperjs/core
npm WARN material-ui-pickers@2.2.4 requires a peer of @material-ui/core@^3.2.0 but none is installed. You must install 
peer dependencies yourself.
npm WARN restaurant_project@1.0.0 No description
npm WARN restaurant_project@1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ popper.js@1.16.1
updated 1 package and audited 12007 packages in 14.471s
found 0 vulnerabilities

build again:

no dice

ERROR in ./src/components/StepSlider/StepSlider-view.jsx
Module not found: Error: Can't resolve '@material-ui/lab/Slider' in 'D:\GIT\...\src\components\StepSlider'
 @ ./src/components/StepSlider/StepSlider-view.jsx 2:0-45 29:26-32
 @ ./src/components/StepSlider/index.js
 @ ./src/components/plan_option_slider/PlanOptionSlider-view.jsx
 @ ./src/components/plan_option_slider/index.jsx
 @ ./src/features/plans/plans-view.jsx
 @ ./src/features/plans/index.jsx
 @ ./src/App.jsx
 @ ./src/index.jsx

I'll try w/ the new popper

npm install @popperjs/core

npm WARN material-ui-pickers@2.2.4 requires a peer of @material-ui/core@^3.2.0 but none is installed. You must install 
peer dependencies yourself.
npm WARN restaurant_project@1.0.0 No description
npm WARN restaurant_project@1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ @popperjs/core@2.0.0
added 1 package from 1 contributor and audited 12008 packages in 19.887s
found 0 vulnerabilities

I'm lost, any help would be REALLY appreciated

https://material-ui.com/guides/migration-v3/

[Container] Moved from @material-ui/lab to @material-ui/core.

-import Container from '@material-ui/lab/Container';
+import Container from '@material-ui/core/Container';

after reading this I tested to see if they moved Slider too, they did.

import Slider from '@material-ui/lab/Slider';

should be

import Slider from '@material-ui/core/Slider';

Hope this saves someone else the time I wasted

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM