menu
announcement

Spectrum is now read-only. Learn more about the decision in our official announcement.

infrastructure

Infrastructure-Components let you configure your React App Infrastructure easily

Channels
Team

Error while trying to import css files from node_modules

January 13, 2020 at 6:07pm

Error while trying to import css files from node_modules

January 13, 2020 at 6:07pm
Hello, I get the error 'SyntaxError: Unexpected token . ' from config.js file in .infrastructure_temp folder. It happens when I try to build a project, which imports a css file from react-datepicker module. It seems that the build process try to import it as a js module and not as css file, it also happens when I import another module, that use in its own css file. Thank you.

January 13, 2020 at 6:56pm
Hi, could you please post me the place where you import/use the module?
I didn't upload it yet, if that's what you mean. I use 'import 'react-datepicker/dist/react-datepicker.css' in a js file in my project (not the index file). I hope it's clear enough.

January 22, 2020 at 12:24pm
Hi, sorry it took me some time. But I found a solution. You need to import the css like: import '../../node_modules/react-datepicker/dist/react-datepicker.css'; It's a relative path to the module in your node_modules folder. How many folders you'll need to go up ("../") depends on where you're file is located