Code Monkey home page Code Monkey logo

Comments (2)

si458 avatar si458 commented on June 11, 2024

ive spent the day debugging this and i cant figure it out either?
its erroring out here
https://github.com/capacitor-community/electron/blob/f7ce86454469e967b41c1db8f51ddb942d278ca9/src/cli-scripts/common.ts#L91C76-L132
certainly this line
const t = require.resolve(pathSegments.join('/'), { paths: [root] });

from electron.

si458 avatar si458 commented on June 11, 2024

found the issue
if any of the packages sets main, module, types, etc... in package.json and they begin with ./ then it fails on the require.resolve
a work around is to remove the ./ from at least the main value from package.json inside that particular package!
working out why it does this?

CHATGPT reply:
The require.resolve function in Node.js is used to resolve the path of a module. When you pass a module name to require.resolve, Node.js searches for the module and returns the absolute path to the main entry point of the module.

Now, if the main entry in the package.json file of a module starts with ./, it is treated as a relative path. This can cause issues when using require.resolve because the module resolution process may not correctly handle relative paths when resolving the module.

Here's an example to illustrate the issue:

Consider the following package.json:

{
  "name": "example-module",
  "main": "./lib/index.js"
}

If you use require.resolve('example-module'), Node.js will try to resolve the module using the relative path ./lib/index.js from the current working directory. This may not always work as expected, especially if the working directory is different from where the module is located.

To avoid this issue, it's recommended to specify the main entry in package.json without the ./ prefix:

{
  "name": "example-module",
  "main": "lib/index.js"
}

This way, require.resolve will correctly resolve the module based on the module resolution algorithm without any potential issues related to relative paths.

If you provide more details about your specific use case or share some code snippets, I might be able to provide more targeted assistance.

from electron.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.