简体   繁体   中英

Cannot find node module in rails stimulus controller

I have a problem with importing an npm package that I have created into my rails application.

I'm unsure if the problem is in the way I have created the node package or with the rails app.

The package is very simple -> https://www.npmjs.com/package/test-release-stuff

Now when I'm trying to import it into rails (I install it vie yarn and then see it's in the node modules) and I try to import it into my stimulus controller it tells me that it can't find the module. The error literally says:

Error: Cannot find module 'test-release'stuff'

How I'm importing the module?

I'm doing import foo from 'test-release-stuff'

One thing to note is that when I tried that in a simple react todo app it was imported without any issues.

I have a feeling that it might be something with the webpacker config in my rails app (below is the config) or that it might be something with the node packaga packgage.json file, there might be something incorrect there.

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);

then in the production/development/test files I have something like this:

process.env.NODE_ENV = process.env.NODE_ENV || 'production';

const webpackConfig = require('./base');

module.exports = webpackConfig;

It's a rails 6 project.

Turns out it was neither rails app fault or the node package fault.

I'm running the project inside the container. Although I installed once the previous version of that node package, when updating it, the changes were not properly reflected inside the container - I assume at some point the actual yarn command was not firing or that there was some caching involved.

After properly bringing the containers down, running docker-compose build and docker-compose up the changes were reflected and I can use the node package.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM