Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module not found: Error: Can't resolve 'fs' in... #13

Open
maufarinelli opened this issue Jan 22, 2021 · 3 comments
Open

Module not found: Error: Can't resolve 'fs' in... #13

maufarinelli opened this issue Jan 22, 2021 · 3 comments

Comments

@maufarinelli
Copy link

Hey Marco,
Thanks for this package. It is exactly what I was looking for, the ability to use winston in the browser as well

For some reason, I still have this error in devtools console:

ERROR in ./node_modules/winston/dist/winston/tail-file.js
Module not found: Error: Can't resolve 'fs' in '/workspace/webapp/node_modules/winston/dist/winston'
 @ ./node_modules/winston/dist/winston/tail-file.js 9:9-22
 @ ./node_modules/winston/dist/winston/transports/file.js
 @ ./node_modules/winston/dist/winston/transports/index.js
 @ ./node_modules/winston/dist/winston.js
 @ ./node_modules/offsite-logger/index.js
 @ ./src/stores/userStore.ts
 @ ./src/stores/rootStore.ts
 @ ./src/index.tsx

ERROR in ./node_modules/winston/dist/winston/transports/file.js
Module not found: Error: Can't resolve 'fs' in '/workspace/webapp/node_modules/winston/dist/winston/transports'
 @ ./node_modules/winston/dist/winston/transports/file.js 33:9-22
 @ ./node_modules/winston/dist/winston/transports/index.js
 @ ./node_modules/winston/dist/winston.js
 @ ./node_modules/offsite-logger/index.js
 @ ./src/stores/userStore.ts
 @ ./src/stores/rootStore.ts
 @ ./src/index.tsx

My code is that:

import winston, { configure } from 'winston';
import BrowserConsole from 'winston-transport-browserconsole';
import { OffsiteLoggerOptions } from 'offsite-logger';

export const createOffsiteLoggerForBrowser = ({ service, moniker }: OffsiteLoggerOptions): any => {
  configure(
    new BrowserConsole({
      level: 'info',
    }),
  );

  return winston;
};

and I am bundling with webpack to use in another of our repos

const path = require('path');
const nodeExternals = require('webpack-node-externals');

module.exports = {
  entry: './src/offsite-logger-browser.ts',
  mode: "production",
  module: {
    rules: [
      {
        test: /\.ts?$/,
        use: 'ts-loader',
        exclude: /node_modules/,
      },
    ],
    },
  node: {
    fs: 'empty'
  },
  resolve: {
      extensions: ['.ts', '.js']
  },
  output: {
    filename: 'index.js',
    path: path.resolve(__dirname, 'dist'),
    library: 'offsiteLogger',
    libraryTarget:'commonjs2'
  },
  externals: [nodeExternals()]
};

any idea what I am doing wrong?

@ritvij14
Copy link

ritvij14 commented Mar 3, 2022

Same issue. Did you find a solution for this?

@LinnJS
Copy link

LinnJS commented Feb 21, 2023

Same issue using createLogger with NextJS

@MaximusMcCann
Copy link

ditto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants