找不到模块,当require()与相对路径一起使用时,无法解析文件,
适用于像require("webpack")
这样的东西,但当我尝试指向同一个文件夹中的文件时,例如
require('./init.js')
我得到了无法解决的错误
示例:这是我的代码:
const serviceAccount = require("./jobpost-4d46d-firebase-adminsdk-re9bw-58b8d530cb");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://jobpost-4d46d.firebaseio.com"
});
我最终得到了这个错误:
ERROR in ./src/firebase/index.js
Module not found: Error: Can't resolve './jobpost-4d46d-firebase-adminsdk-re9bw-58b8d530cb' in 'C:\Users\Oluwanifemi\WebstormProjects\jobpostadmin\src\firebase'
@ ./src/firebase/index.js 8:21-82
@ ./src/store/ManageUsersActions.js
@ ./src/store/ManageUserReducer.js
@ ./src/store/index.js
@ ./src/index.js
@ multi (webpack)-dev-server/client?http://localhost:8080 ./src/index.js
我使用webpack v4 with config
module.exports = {
target: 'node', // To stop the 'fs' error problem
entry: [
'./src/index.js'
],
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader",
options: {
presets: ["es2015"]
}
},
{
test: /\.css$/,
use: [ 'style-loader', 'css-loader' ]
}
]
},
// resolve: {
// extensions: ['*', '.js', '.jsx']
// },
output: {
path: __dirname + '/build',
publicPath: '/',
filename: 'bundle.js'
},
devServer: {
contentBase: './build'
},
node: {
fs: 'empty'
}
};