Shopware 6: ModuleNotFoundError: Module not found: Error: Can’t resolve ‘flatpickr’

Good morning! Yesterday it took me half a day to get the build-admin.sh working.

The problem was that the error “ModuleNotFoundError: Module not found: Error: Can’t resolve ‘flatpickr'” was thrown and I had no clue why. And after running down the rabbit hole the funny developer-game started “which of the many changes was the one which made it work?”

What was wrong: Adding a webpack.config.js

I have no clue about all the frontend stuff and give my best to avoid it, but as you can see, sometimes I fail. My first thought was, that the shopware js builder doesn’t find the dependency, so I added a webpack.config.js.

They look like this and define the paths to your config libs (for webpack?)

const path = require('path');

module.exports = () => {
    return {
        resolve: {
            alias: {
                // The module "SwagBasicExample" is looked for in
                // <current directory>/../src
                SwagBasicExample: path.join(__dirname, '..', 'src')
            }
        }
    };
};

In some examples you find node_modules in the path.join() which totally makes sense, when your library is living in there. But from everything I understand Shopware is smart enough to pick up the packages.json files and the node_modules directories. Unfortunately it is NOT smart enough to run npm install for you.

The solution: npm install

So the solution was super easy: Run npm install and shopware takes care of the rest.

ModuleNotFoundError: Module not found: Error: Can't resolve 'date-fns/esm/format' in '/var/www/html/custom/static-plugins/PluginA/node_modules/date-fns-tz/esm/format'

More weird errors to come. That was a hard one. It took a while until I realised, that this dependency is just missing in the packages.json

npm install date-fns helped.

Leave a Reply