Unable to resolve character using ES6 import syntax

Here is an example of how to import specific classes from a module:

import {ModalContainer, ModalDialog} from 'react-modal-dialog'; 

However, PhpStorm (latest EAP) gives me an error:

Unable to resolve 'ModalDialog' character

I installed the package with npm install react-modal-dialog and it is present in node_modules .

Equivalent to var {ModalContainer, ModalDialog} = require('react-modal-dialog'); works great.

+5
source share
2 answers

I think this is caused by PHPStorm. The IDE cannot understand import syntax when importing a CommonJS module.

I got this warning when using WebStorm 2016.1.2 too.

Taking react and react-router as an example:

  • react is a CommonJS module developed using ES5 syntax;
  • react-router developed using ES2015 syntax and compiled by Babel.

WebStorm 2016.1.2 may allow Link exported by the react-router module, but cannot allow createClass exported by the react module.

Update

browser-sync is a CommonJS module developed with ES5. But it works well on WebStorm, WebStorm can allow all APIs exported by browser-sync .

This baffled me that WebStorm could not allow the exported react API.

+4
source

I came across this when setting up a React project, and all I did was download the typescript import definition , in my case I was just looking for react .

enter image description here

Instructions for adding libraries to your project can be found on the webstorm help page .

+2
source

Source: https://habr.com/ru/post/1244278/


All Articles