我正在用一个使用babel transpiler的es6编写节点应用程序.
我有2个文件index.js和my-module.js我的根目录
- index.js
- my-module.js
Run Code Online (Sandbox Code Playgroud)
我-module.js
export let myFunc = () => {
console.log('myFunc was called!!!');
}
Run Code Online (Sandbox Code Playgroud)
index.js
import {myFunc} from './my-module';
myFunc();
Run Code Online (Sandbox Code Playgroud)
如果我从命令行运行以下行,一切都按预期工作.
$ babel-node index.js >> myFunc was called!!!
Run Code Online (Sandbox Code Playgroud)
但是如果我在导入my-module时删除了点:
import {myFunc} from '/my-module';
myFunc();
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
Error: Cannot find module '/my-module'
Run Code Online (Sandbox Code Playgroud)
我无法使用绝对路径导入模块的任何原因?无论如何改变.babelrc配置来支持它?
谢谢
我有一个基于React Redux Starter Kit的 React 项目。
在 Jest 测试中:当我尝试使用基于根的路径(如“组件/链接”)导入某些内容时 - 它不起作用。只有相对路径有效。
推杆
{ "jest": { "rootDir": "<rootDir>/src" } }
Run Code Online (Sandbox Code Playgroud)
在文件package.json 中中不起作用。
还有其他方法吗?
{
"name": "react-redux-starter-kit",
"version": "3.0.0-alpha.2",
"description": "",
"main": "index.js",
"engines": {
"node": ">=4.5.0",
"npm": "^3.0.0"
},
"scripts": {
"clean": "rimraf dist",
"compile": "better-npm-run compile",
"lint": "eslint bin build config server src tests",
"lint:fix": "npm run lint -- --fix",
"start": "better-npm-run start",
"dev": "better-npm-run dev",
"test": "jest",
"test:dev": "npm run test …Run Code Online (Sandbox Code Playgroud)