Coder Social home page Coder Social logo

Cannot compile `examples/submodule` about v HOT 13 CLOSED

weezy20 avatar weezy20 commented on August 25, 2024
Cannot compile `examples/submodule`

from v.

Comments (13)

spytheman avatar spytheman commented on August 25, 2024 1

The path to the compiled project also matters (whether it is relative or absolute):

#0 20:03:06 ᛋ master /v/oo❱./v   examples/submodule/main.v
examples/submodule/main.v:1:1: builder error: bad module definition: examples/submodule/v imports module "mymodules" but /space/v/oo/examples/submodule/mymodules/main_functions.v is defined as module `mymodule`
    1 | import mymodules { add_xy }
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    2 | import mymodules.submodule { sub_xy }
    3 |
#1 20:03:12 ᛋ master /v/oo❱
#1 20:03:13 ᛋ master /v/oo❱./v   /space/v/oo/examples/submodule/main.v
#0 20:03:17 ᛋ master /v/oo❱

from v.

felipensp avatar felipensp commented on August 25, 2024

For me it is:

main.v:1:1: builder error: bad module definition: v imports module "mymodules" but /home/felipe/github/v/examples/submodule/mymodules/main_functions.v is defined as module `mymodule`
    1 | import mymodules { add_xy }
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    2 | import mymodules.submodule { sub_xy }
    3 |

from v.

weezy20 avatar weezy20 commented on August 25, 2024

For me it is:

main.v:1:1: builder error: bad module definition: v imports module "mymodules" but /home/felipe/github/v/examples/submodule/mymodules/main_functions.v is defined as module `mymodule`
    1 | import mymodules { add_xy }
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    2 | import mymodules.submodule { sub_xy }
    3 |

Try changing mymodules to mymodule.. I guess the latter is the module name.

from v.

JalonSolov avatar JalonSolov commented on August 25, 2024

No, the fix for @felipensp 's problem is to change the module line at the top of mymodules/main_function.v to module mymodules instead of the current module mymodule (which doesn't match the subdir name, so is patently incorrect).

For @weezy20 it looks like the original example was modified, as that's not the way it looks in the repo.

from v.

weezy20 avatar weezy20 commented on August 25, 2024

No, the fix for @felipensp 's problem is to change the module line at the top of mymodules/main_function.v to module mymodules instead of the current module mymodule (which doesn't match the subdir name, so is patently incorrect).

For @weezy20 it looks like the original example was modified, as that's not the way it looks in the repo.

I believe something was modified to make the example run (I don't know v) when I ran and copied the stderr. But in any case, isn't expected behaviour that this runs out of the box without any modifications? That's what I'm reporting in essence.

from v.

JalonSolov avatar JalonSolov commented on August 25, 2024

Yes, that is the expected behavior. It definitely needs a fix.

Locally, you can try one fix by editing examples/submodule/mymodules/main_function.v and adding an s to the end of the first line, so that it says module mymodules.

That will fix what @felipensp reported.

Then try git restore main.v in the examples/submodule directory. That will hopefully fix what you're seeing, as well, so it should all work as expected.

We will have to get a PR in to fix the import in main_function.v.

from v.

weezy20 avatar weezy20 commented on August 25, 2024

image
changed module mymodule -> module mymodules in file mymodules/main_function.v

Yet I get this result when running single file via vs-code. strangely, I cannot run this code still using v run main.v
however, if I use the absolute path, I don't get this error, and the code runs fine.

from v.

weezy20 avatar weezy20 commented on August 25, 2024

Might be just speculation but is it possible this has something to do with the os.real_path function defined in os.j.v which uses realPathSync node API ? I just had someone tell me that they've experienced a similar issue i.e. module resolution failure in javascript when using nodejs on relative paths vs absolute path.

from v.

JalonSolov avatar JalonSolov commented on August 25, 2024

os.js.v will only be used if you tell V to output JavaScript.

from v.

Jopestpe avatar Jopestpe commented on August 25, 2024

(This message was translated, Sorry for any English mistakes)
For me, it worked when I replaced 'mymodules' -> 'mymodule'.

|-- main.v
|-- mymodule
|   |-- main_functions.v
|   `-- submodule
|       `-- sub_functions.v
`-- v.mod

main.v

import mymodule { add_xy }
import mymodule.submodule { sub_xy }

main_functions.v

module mymodule
$ v run main.v
5
3

I got curious because I tested with other letters and numbers, and they all worked, except for the letter ‘s’.

from v.

JalonSolov avatar JalonSolov commented on August 25, 2024

That's... really odd. The trailing s shouldn't make any difference at all.

from v.

ttytm avatar ttytm commented on August 25, 2024

Reason is that the modules path is searched for local modules if we come across it. We are just a little bit too loose when checking the path.

from v.

spytheman avatar spytheman commented on August 25, 2024

On this PR: #21083, using both a relative and an absolute path works correctly.

from v.

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.