最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - "Cannot resolve symbol" when using ES6 `import` syntax - Stack Overflow

programmeradmin2浏览0评论

Here an example is given how to import certain classes from a module:

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

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

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

The equivalent var {ModalContainer, ModalDialog} = require('react-modal-dialog'); works fine.

Here an example is given how to import certain classes from a module:

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

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

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

The equivalent var {ModalContainer, ModalDialog} = require('react-modal-dialog'); works fine.

Share Improve this question edited Mar 2, 2016 at 11:14 LazyOne 165k47 gold badges413 silver badges415 bronze badges asked Mar 2, 2016 at 8:22 AndreKRAndreKR 33.7k21 gold badges115 silver badges176 bronze badges 5
  • 1 Have you set the js language version to ECMA script harmony? – winhowes Commented Mar 2, 2016 at 8:30
  • Are you transpiling the code before executing it? – Mulan Commented Mar 2, 2016 at 8:41
  • 2 @winhowes Yes, happens in both "ECMAScript 6" and "JSX Harmony" mode. – AndreKR Commented Mar 2, 2016 at 13:02
  • I think destructuring doesn't work with import. I have to do import React from 'react-native'; and then var { Text, View } = React to workaround the warning. – Sam Commented Mar 3, 2016 at 8:29
  • It's not destructuring (at least it's not meant to be), it's the import syntax: "Import multiple members of a module. This inserts both foo and bar into the current scope." – AndreKR Commented Mar 3, 2016 at 9:42
Add a comment  | 

2 Answers 2

Reset to default 12

I encountered this when setting up a React project and all i did was download the import's typescript definition, in my case just searched for react.

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

I think it caused by PHPStorm. The IDE can't understand the import syntax when import a CommonJS module.

I got this warning when using WebStorm 2016.1.2, too.

Taking react and react-router as example:

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

WebStorm 2016.1.2 can resolve Link exported by react-router module, but can't resolve createClass exported by react module.

Update:

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

It baffled me that WebStorm can't resolve react exported API.

发布评论

评论列表(0)

  1. 暂无评论