How can I import a JS file with special characters in it's name in React and JSX?

440 Views Asked by At

How can I import a JS file with special characters in it's name in React and JSX?

I can

import { tomorrow} from 'react-syntax-highlighter/dist/esm/styles/hljs';

(the folder contains tomorrow.js and tomrorrow-night.js)

but I can't:

import { tomorrow-night} from 'react-syntax-highlighter/dist/esm/styles/hljs';

I don't think destructuring works here because it's an import statement.

2

There are 2 best solutions below

2
On BEST ANSWER

you can try as

import * as Highlighter from 'react-syntax-highlighter/dist/esm/styles/hljs';

const TomorrowNight = Highlighter[`tomorrow-night`];
1
On

How about using the import * as blah import? That gives you an object that you can then lookup any string in.

import * as tmrw from from 'react-syntax-highlighter/dist/esm/styles/hljs';
const tmrw_night = tmrw['tomorrow-height']