我有一个使用webpack编译的Node.js应用程序。编译我的应用程序并运行它后,我收到以下错误:
Error: Cannot find module 'oracledb'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at t.(anonymous function).i (C:\Users\xxx\Documents\xxx\web-test-nodejs\dist\api\bundled.js:1:400)
at Object.<anonymous> (C:\Users\xxx\Documents\xxx\web-test-nodejs\dist\api\bundled.js:1:1982)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\xxx\Documents\xxx\web-test-nodejs\index.js:19:14)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
我没有使用oracledb,并在我的webpack配置文件中明确排除了它(包含在下面)。我正在使用带有knex的mysql,我相信knex是导致此错误的原因。我怎样才能摆脱这个错误?
module.exports = [{
entry: [
'./src/api/index.js',
],
module: {
rules: [{
test: /\.js$/,
exclude: externalNodeModules,
},
{
test: /\.js$/,
exclude: externalNodeModules,
loader: 'eslint-loader',
enforce: 'pre',
},
{
test: /\.js$/,
exclude: externalNodeModules,
loader: 'babel-loader',
options: {
presets: ['env'],
},
},
{
test: /\.(html)$/,
use: {
loader: 'html-loader',
options: {
attrs: [':data-src'],
},
},
},
],
},
node: {
__dirname: true,
},
target: 'node',
externals: {
'sqlite3': 'sqlite3',
'mariasql': 'mariasql',
'mssql': 'mssql',
'mysql2': 'mysql2',
'oracle': 'oracle',
'strong-oracle': 'strong-oracle',
'oracledb': 'oracledb',
'pg': 'pg',
'pg-query-stream': 'pg-query-stream',
},
output: {
path: path.join(__dirname, 'dist', 'api'),
filename: 'bundled.js',
libraryTarget: 'umd',
},
resolve: {
modules: [
'node_modules',
'src/node_modules',
'src',
],
},
plugins: [
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false,
}),
new webpack.optimize.UglifyJsPlugin({
beautify: false,
mangle: {
screw_ie8: true,
keep_fnames: true,
},
compress: {
screw_ie8: true,
},
comments: false,
}),
],
}, {
entry: {
'index': './src/entry/app.js',
'404': './src/entry/404.js',
},
module: {
rules: [{
test: /\.js$/,
exclude: [
externalNodeModules,
path.resolve(__dirname, 'src/static/js/third_party'),
],
loader: 'eslint-loader',
enforce: 'pre',
},
{
test: /\.js$/,
exclude: externalNodeModules,
loader: 'babel-loader',
options: {
presets: ['env'],
},
},
{
test: /\.css$/,
exclude: externalNodeModules,
use: extractCSS.extract({
fallback: 'style-loader',
use: 'css-loader',
}),
},
{
test: /\.(eot|svg|ttf|woff|woff2)$/,
exclude: externalNodeModules,
loader: 'url-loader?limit=30000&name=font/[name].[ext]',
},
{
test: /\.(png|jpg|gif|ico)$/,
exclude: externalNodeModules,
loader: 'file-loader?name=img/[name].[ext]',
},
],
},
output: {
publicPath: '/',
path: path.join(__dirname, 'dist', 'web', 'static'),
filename: 'js/[name].js',
},
plugins: [
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false,
}),
new webpack.optimize.UglifyJsPlugin({
beautify: false,
mangle: {
screw_ie8: true,
keep_fnames: true,
},
compress: {
screw_ie8: true,
},
comments: false,
}),
new CleanWebpackPlugin(['dist']),
extractCSS,
new webpack.ProvidePlugin({
'$': 'jquery',
'jquery': 'jquery',
'jQuery': 'jquery',
'window.$': 'jquery',
'window.jquery': 'jquery',
'window.jQuery': 'jquery',
}),
new CopyWebpackPlugin([{
from: 'views/**/*.pug',
context: 'src/',
to: '..',
},
{
from: 'img/profile/**/*.{jpg,gif,png}',
context: 'src/static/',
},
]),
],
}];
修改
在运行node index.js
答案 0 :(得分:0)
在安装knex后,您似乎需要安装其中一个模块:
http://knexjs.org/#Installation-node
首先:
npm install knex --save
然后:
npm install mysql --save
我希望安装mysql会阻止它查找oracledb
还要确保将客户端指定为mysql:
var knex = require('knex')({
client: 'mysql',
connection: {
host : '127.0.0.1',
user : 'your_database_user',
password : 'your_database_password',
database : 'myapp_test'
}
});
同时删除webpack配置中对Oracledb的引用。