Search code examples
reactjsnpmgitlabyarn-v2

Module not found: Can't resolve 'x' in 'y' from Package Registry


I recently created my very first package in my project's Package Registry through GitLab.

It was published correctly and I was even able to yarn add ... the package in question to another repo.

Checking the node_modules I can see the package present. However, when I run import I am told that the module was not found.

I assume I'm either importing badly or exporting badly (or maybe both)

My package.json of the file I am exporting from has the following:

{
  "name": "@thing/thing2",
  "version": "0.1.2",
  "private": false,
  "dependencies": {
    "many packages"
  },
  "scripts": {
    "start": "react-scripts start",
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "publishConfig": {
    "something"
  },
  "main": "./src/index.js",
  "type": "module",
  "license": "MIT"
}

The component I am after lives in src/thing1/file.jsx And I'm importing the file as:

import {stuff} from "@thing/thing2" 

I'm sure there is documentation online for how to do this but I'm clearly searching for it wrong, thanks.


Solution

  • I needed to add:

      "type": "module",
      "module": "./src/module-export.jsx",
    

    to the package file.