I'm facing an issue with integrating my own npm package into a Rails application that I have developed.
It's unclear whether the problem lies in the creation of the node package or within the rails app itself.
The package in question is fairly simple - you can find it here: https://www.npmjs.com/package/test-release-stuff
When attempting to import this package into my Rails project (after installing it via yarn and confirming its presence in the node modules), I encounter an error while trying to import it into my stimulus controller. The error message states:
Error: Cannot find module 'test-release'stuff'
Here is how I am importing the module:
I use the following syntax:
import foo from 'test-release-stuff'
An interesting observation is that when I tested the import in a basic React todo application, it worked seamlessly without any issues.
I suspect that the problem may lie within the webpacker configuration in my Rails app (see the config below) or there could be an error in the package.json file of the node package itself.
const { webpackConfig, merge } = require('@rails/webpacker');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const plugins = [];
if (process.env.ANALYZE === 'true') {
plugins.push(new BundleAnalyzerPlugin());
}
const customConfig = {
resolve: {
extensions: ['.css'],
},
plugins: plugins,
};
module.exports = merge(webpackConfig, customConfig);
For the production/development/test files, my setup looks something like this:
process.env.NODE_ENV = process.env.NODE_ENV || 'production';
const webpackConfig = require('./base');
module.exports = webpackConfig;
This project is built on Rails 6.