【发布时间】:2016-09-26 08:59:56
【问题描述】:
我正在尝试在npm (this one) 上发布我正在使用webpack 和babel 开发的包。我的代码是用ES6 编写的。我的源文件中有一个文件index.js,它(目前)导出了我的库的一个核心组件,它就像这样:
import TheGamesDb from './scrapers/thegamesdb';
export { TheGamesDb };
我正在使用 webpack 和 babel 创建一个 dist index.js 这是我的包的主文件。我的webpack.config.js 是这样的:
const webpack = require('webpack');
const nodeExternals = require('webpack-node-externals');
module.exports = {
entry: {
index: ['babel-polyfill', './src/index.js'],
development: ['babel-polyfill', './src/development.js']
},
output: {
path: '.',
filename: '[name].js',
library: 'rom-scraper',
libraryTarget: 'umd',
umdNamedDefine: true
},
devtool: 'source-map',
module: {
loaders: [
{ test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/ }
]
},
target: 'node',
externals: [nodeExternals()]
};
现在当我在另一个项目中加载我的包并尝试 import 我的导出 TheGamesDb 就像这样
import { TheGamesDb } from 'rom-scraper';
我得到了错误
未捕获的类型错误:路径必须是字符串。收到未定义
需要注意的是,我正在将我的库导入electron。
更新:Electron 似乎是这里的主要问题,它甚至不是我的库,而是引发此错误的依赖项(仅在 Electron 中)
【问题讨论】:
标签: javascript npm webpack electron babeljs