首页 > 解决方案 > npm package works locally but modules cannot be resolved when published

问题描述

I wrote a little npm module. In the main index.js, I am requiring another js file like so:

const Interface = importJsx('./Interface');

interface.js is a functional react component which I am exporting by writing module.exports = Interface; at the end and is in the root folder, just like index.js. When I run node index.js on the command line, everything works. When I publish the module to npm and run npx MY_PACKAGE_NAME, all of a sudden 'Interface' cannot be resolved. What is the workaround for npm's busted file system?

标签: node.jsnpm

解决方案


推荐阅读