fs.exists is not a function in node env
See original GitHub issueI am trying to use this package in node, not browser environment.
When I ran the code below, I got this error: TypeError: fs.exists is not a function (https://github.com/exceljs/exceljs/blob/76a205ced964e0a9c3f14addadb8156a442e45a5/lib/utils/utils.js#L129)
import * as Excel from "exceljs/dist/exceljs.js";
const filepath = 'C:\\Documents\\projects\\tmpls\\abcdedf.xlsx';
const workbook = new Excel.Workbook();
await workbook.xlsx.readFile(filepath).then(()=>{console.log(23456)}).catch((e)=>{console.log('[catch]', e)});
My webpack.config:
var path = require('path');
var webpack = require('webpack');
module.exports = {
entry: {
index: './src/core/index.js'
},
output: {
path: path.join(__dirname, './dist'),
filename: '[name].js'
},
resolve: {
extensions: ['.js', '.jsx']
},
target: 'node',
module: {
loaders: [
{
test: /\.js|jsx$/,
loader: 'babel-loader',
exclude: /node_modules/
}
]
}
}
Is there anything wrong with the way I use the package or my webpack.config?
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Uncaught TypeError: fs.exists is not a function - Stack Overflow
I am having trouble with the fs module error in Node JS Application. I am using Webpack also,. My .js file: const fs...
Read more >Node.js fs.exists() Method - GeeksforGeeks
The fs.exists() method is used to test whether the given path exists or not in the file system. Syntax: fs.exists( path, callback )....
Read more >Process | Node.js v19.3.0 Documentation
The 'beforeExit' event is emitted when Node.js empties its event loop and has no additional work to schedule. Normally, the Node.js process will...
Read more >Node.js — Check If a Path or File Exists - Future Studio
Asynchronously Check if a File Exists in Node. js. The fs module in Node. js comes with a deprecated exists method.
Read more >What is the Node fs.exists() method? - Educative.io
The method returns a boolean value. exists() returns true if the file or path exists in the directory, and false if the file...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Finally figured it out
webpack.config.js: need to set node_modules as externals
.babelrc: actually not related to this issue, but just my own code using the await/async
code:
@kigh-ota
I am using babel 6. This is my babelrc
Since I excluded the node_modules in the webpack, is babel still going to compile the exceljs?
I used the node v8.4.0 at the beginning. Then I upgraded to v12.13.0. It doesn’t fix the issue.