grimmdude / MidiWriterJS

♬ A JavaScript library which provides an API for programmatically generating and creating expressive multi-track MIDI files and JSON.
MIT License
557 stars 60 forks source link

Error: Module not found: Error: Can't resolve 'fs' #49

Closed jongwon-park closed 5 years ago

jongwon-park commented 5 years ago

An error occurs in v1.7.0 as shown below.

ERROR in ./node_modules/midi-writer-js/build/index.js Module not found: Error: Can't resolve 'fs' in '......./node_modules/midi-writer-js/build'

Perhaps, const fs = require('fs'); of saveMIDI function in Writer class is the problem.

grimmdude commented 5 years ago

Hi @jongwon-park,

Thanks for your message. Weird, I'm not able to replicate this error on my end. Could you give me a little more info about your environment and the context in which you're using this method when you get the error?

-Garrett

jongwon-park commented 5 years ago

My environment is angular v6.1.6 webpack v4.9.2 node 10.14.1

this is my webpack.config.js

const path = require('path');
const webpack = require('webpack');
/**
 * This is a server config which should be merged on top of common config
 */
module.exports = {
    mode: 'development',
    externals: [/(node_modules|main\..*\.js)/],

    entry: {
        // This is our Express server for Dynamic universal
        server: './server.ts',
        // This is an example of Static prerendering (generative)
        prerender: './prerender.ts',
    },
    resolve: { extensions: ['.js', '.ts'] },
    output: {
        // Puts the output at the root of the dist folder
        path: path.join(__dirname, 'dist'),
        filename: '[name].js'
    },

    plugins: [
        new webpack.ContextReplacementPlugin(
            // fixes WARNING Critical dependency: the request of a dependency is an expression
            /(.+)?angular(\\|\/)core(.+)?/,
            path.join(__dirname, 'src'), // location of your src
            {} // a map of your routes
        ),
        new webpack.ContextReplacementPlugin(
            // fixes WARNING Critical dependency: the request of a dependency is an expression
            /(.+)?express(\\|\/)(.+)?/,
            path.join(__dirname, 'src'),
            {}
        )
    ],
    target: 'node',
    node: {
        __dirname: false
    },
};

midi-writer-js v1.6.0 works very well in my environment. I get the error when I run the ng serve command using v1.7.0 midi-writer-js only.

grimmdude commented 5 years ago

Hi @jongwon-park,

I think this might be related to webpack. Check this comment for possible resolution: https://github.com/webpack-contrib/css-loader/issues/447#issuecomment-285598881

-Garrett