0

I want to export some of my CRA components to an external NPM package. I created a package.json file inside my Components and set the main to index.ts. The index.ts file contains an import and export of the wanted components.

I then run npm publish on the components folder and install it in another project.
The other project is able to identify the components with the correct needed type (props) but it won't compile.

I get the following error:

Module parse failed: Unexpected token (8:23)
File was processed with these loaders:
 * ./node_modules/@pmmmwh/react-refresh-webpack-plugin/loader/index.js
 * ./node_modules/source-map-loader/dist/cjs.js
You may need an additional loader to handle the result of these loaders.
| import './style.scss';
| 
> const Footer = ({links}: FooterProps) => {
Nir Tzezana
  • 2,275
  • 3
  • 33
  • 56
  • Looks like you need ts-loader or babel/preset-typescript or some way to compile your ts to js. No way for anyone to know without more info, ideally an MRE. You are probably not publishing compiled code. – morganney Dec 20 '22 at 14:13
  • @morganney This is as basic is it goes, it's a simple CRA that I want to export components from, there isn't anything that I changed from the original CRA. – Nir Tzezana Dec 20 '22 at 14:54
  • `Set the main to index.ts` sounds wrong. `I then run npm publish on the components folder` sounds wrong (where's the build step). `but it won't compile` sounds interesting but nobody knows how you are attempting to compile. Its up to you whether you want to share more or not, but what you've got so far is full of questions. Check out [this](https://stackoverflow.com/questions/52268320/module-parse-failed-unexpected-token) similar question, it provides more useful debugging info, maybe it will help you or maybe you can use it as an example of what to share in your question. – morganney Dec 20 '22 at 14:57

0 Answers0