question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: The package may have incorrect main/module/exports

See original GitHub issue

Description

The package.json of the csstype project is not declaring the main file and that is causing an error with vite.

The error appears to be a conflict since it doesn’t appear unless you add some other packages, but the problem is caused in just this package (if you’re using it (has it exported in your code)) and can be solved by declaring this main file of the package in the package.json.

Screenshots

Screenshot_2022-05-09_15-22-37 Screenshot_2022-05-09_15-22-59

To Reproduce

Before starting the reproduction, the csstype version of the reproduction is 2.6.20, and the project dependencies created will be with this versions:

  "dependencies": {
    "@vueuse/core": "^8.4.2",
    "vue": "^3.2.25"
  },
  "devDependencies": {
    "@vitejs/plugin-vue": "^2.3.1",
    "typescript": "^4.5.4",
    "vite": "^2.9.7",
    "vue-tsc": "^0.34.7"
  }

Reproducing:

Create the project that has the csstype dependence and add a package that can cause a confict. In the terminal, run:

yarn create vite testing --template vue-ts && cd testing && yarn add @vueuse/core

Import the csstype:

Open the project (code . if you use VSC).

At src/App.vue add import { Color } from 'csstype'; at the <script setup lang="ts">. It will be like that:

<script setup lang="ts">
// This starter template is using Vue 3 <script setup> SFCs
// Check out https://vuejs.org/api/sfc-script-setup.html#script-setup
import HelloWorld from './components/HelloWorld.vue'
import { Color } from 'csstype';
</script>

Getting the error:

Try to run the project in your terminal:

yarn dev

You’ll get the error:

yarn run v1.22.17
$ vite

  vite v2.9.8 dev server running at:

  > Local: http://localhost:3000/
  > Network: use `--host` to expose

  ready in 188ms.

✘ [ERROR] [plugin vite:dep-scan] Failed to resolve entry for package "csstype". The package may have incorrect main/module/exports specified in its package.json: Failed to resolve entry for package "csstype". The package may have incorrect main/module/exports specified in its package.json.
...

Validations

  • - The provided reproduction is a minimal reproducible example of the bug.
  • - Readed the README (docs).
  • - Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.

Fixing the bug

As said by the vite, The package may have incorrect main/module/exports specified in its package.json, the fix is therefore simple, its needed to add a primary entry point to the program. I fixed it and submitted a PR. Hope that it’s pulled soon or solved in any other possible way.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
luigiMinardicommented, May 16, 2022

So, lets see if I understood right. The bundler will ignore the import followed by type and that is why you can bundle the app even with the package being buggy, is it right?

@luigiMinardi Not a bug on the csstype side of things. Because this is a type-only package, there is no JS to link to in a main field. For example, @types/react provides a main value of "" as well (link). vite’s dep-scan command should probably ignore packages with a blank main value. It’s a missing check on their end.

Ooh, understood, thanks for the info. I’ll close the issue since everything was done on the csstype side 😃

2reactions
meyercommented, May 16, 2022

So, lets see if I understood right. The bundler will ignore the import followed by type and that is why you can bundle the app even with the package being buggy, is it right?

@luigiMinardi Not a bug on the csstype side of things. Because this is a type-only package, there is no JS to link to in a main field. For example, @types/react provides a main value of "" as well (link). vite’s dep-scan command should probably ignore packages with a blank main value. It’s a missing check on their end.

Read more comments on GitHub >

github_iconTop Results From Across the Web

bug: the package may have incorrect main/module/exports ...
[commonjs] Failed to resolve entry for package "objectorarray". The package may have incorrect main/module/exports specified in its package.json ...
Read more >
reactjs - Failed to resolve entry for package "notistack5 ...
The package may have incorrect main/module/exports specified in its package.json: Failed to resolve entry for package "notistack5". The package ...
Read more >
monaco-editor-vite-fix - NPM Package Overview
Error : Failed to resolve entry for package "monaco-editor". The package may have incorrect main/module/exports specified in its package.json ...
Read more >
Modules: Packages | Node.js v19.3.0 Documentation
Such modules are passed through the cjs-module-lexer to try to identify named exports, which are available if they can be determined through static...
Read more >
Package exports
Any other requests will lead to a ModuleNotFound Error. ... For properties ending with * , * may take any value and any...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found