我的项目结构:
/website
/node
/node_module <<-- library root
/type_src <<-- ts files
/src <<-- compiled js files
我曾经能够像这样自动导入根 Node 模块:
/type_src/store/BaseStore.ts:
import {observer} from "mobx-react/native";
@observer
class BaseStore{
}
但最近,自动导入为这些 Node 模块生成了相对路径:
import {observer} from "../../node_modules/mobx-react/index";
@observer
class BaseStore{
}
生成 import {observer} from "mobx-react/native";
的唯一方法是等待那个红色灯泡出现,这不太方便。
我已经创建了另一个项目并且它工作正常,但我不知道为什么这个项目突然出现这个问题。谁能帮我解决这个问题?
配置文件:
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"moduleResolution": "node",
"removeComments": true,
"allowSyntheticDefaultImports": true,
"noImplicitAny": false,
"sourceMap": true,
"outDir": "./src",
"jsx": "react",
"experimentalDecorators": true,
"noLib": false,
"declaration": false,
"emitDecoratorMetadata": true,
"lib": ["es6", "dom"],
"types": ["reflect-metadata"]
},
"exclude": [
"node_modules"
]
}
最佳答案
根据引用链接,它是(已修复)webstorm 中的错误。
解决方案 - 升级到 2017.1 或更高版本
关于node.js - 为什么在PhpStorm/WebStorm中自动导入生成根 Node 模块的相对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42464774/