Skip to content

unable to import from library (ascMain not working?) #1679

Closed

Description

@trusktr

Code is here: lume/glas#111

asc v0.17.7

I believe ascMain is set up correctly, but it doesn't seem to work.

From that example, here is the aswebglue ascMain field pointing to src/WebGL.ts:

https://github.com/lume/ASWebGLue/blob/9499782e0d7b3b9f51bbe3c7238abf0838f51c71/package.json#L4

  "ascMain": "src/WebGL.ts",

Here is src/WebGL.ts which is located exactly where ascMain points to:

https://github.com/lume/ASWebGLue/blob/9499782e0d7b3b9f51bbe3c7238abf0838f51c71/src/WebGL.ts

Here is the file that tries to import stuff from 'aswebglue' but it doesn't work:

https://github.com/lume/glas/blob/8f56ae0bb0d5796d4202fbfab7a352e00bc44600/src/as/test.ts#L2

import {SHORT} from 'aswebglue'

Steps to reproduce:

git clone git@github.com:lume/ASWebGLue.git
cd ASWebGLue
git checkout assemblyscript-issue-1679
cd src/examples/CubeNodejs
npm install
npm start

That will output the following error:

❯ npm start

> @ prestart /home/trusktr/src/battlelinegames+ASWebGLue/src/examples/CubeNodejs
> npm run build


> @ build /home/trusktr/src/battlelinegames+ASWebGLue/src/examples/CubeNodejs
> asc cube.ts -b cube.wasm

ERROR TS6054: File '~lib/aswebglue/src/WebGL.ts' not found.

 import {WebGLRenderingContext, WebGLShader, WebGLProgram} from 'aswebglue/src/WebGL'; // does not work
                                                                ~~~~~~~~~~~~~~~~~~~~~
 in cube.ts(2,64)

FAILURE 1 parse error(s)

Activity

  1. p3nGu1nZz commented on Feb 13, 2021

    @p3nGu1nZz

    I was able to reproduce the bug. I found a work around by explicitly declaring the relative path. Looks like its using the LIBRARY_PREFIX path regardless if its a defined as a USER source library by the parser.ts.

    work around:

    import {SHORT} from '../../node_modules/aswebglue/src/webgl'
  2. dcodeIO commented on Feb 14, 2021

    @dcodeIO
    Member

    When I follow the reproduction steps, I get a version of aswebglue in node_modules that has "ascMain": "webgl.ts",. Could this be a dependency problem?

    Also, src/test.ts does not exist.

  3. trusktr commented on Feb 14, 2021

    @trusktr
    MemberAuthor

    The commit hashes to use are above in the OP links.

    lume/glas repo: 8f56ae0bb0d5796d4202fbfab7a352e00bc44600

    aswebglue: 9499782e0d7b3b9f51bbe3c7238abf0838f51c71

    If you checkout lume/glas to that hash, you can modify package.json to have the exact hash for the aswebglue dependency, but it should be reproducible even without doing that.

  4. trusktr commented on Feb 23, 2021

    @trusktr
    MemberAuthor

    @dcodeIO simple reproduction:

    git clone git@github.com:lume/ASWebGLue.git
    cd ASWebGLue
    git checkout assemblyscript-issue-1679
    cd src/examples/CubeNodejs
    npm install
    npm start

    You will see this output:

    ❯ npm start
    
    > @ prestart /home/trusktr/src/battlelinegames+ASWebGLue/src/examples/CubeNodejs
    > npm run build
    
    
    > @ build /home/trusktr/src/battlelinegames+ASWebGLue/src/examples/CubeNodejs
    > asc cube.ts -b cube.wasm
    
    ERROR TS6054: File '~lib/aswebglue/src/WebGL.ts' not found.
    
     import {WebGLRenderingContext, WebGLShader, WebGLProgram} from 'aswebglue/src/WebGL'; // does not work
                                                                    ~~~~~~~~~~~~~~~~~~~~~
     in cube.ts(2,64)
    
    FAILURE 1 parse error(s)
    
  5. trusktr commented on Feb 23, 2021

    @trusktr
    MemberAuthor

    Updated the previous comment, the reproduction is reproducible and won't change.

  6. torch2424 commented on Feb 26, 2021

    @torch2424
    Contributor

    Per @trusktr request, I was able to try to import using import {myExport} from 'my-npm-lib/some-folder-in-the-lib/some-file', and it didn't work for me either in my project:

    Screenshot from 2021-02-26 12-58-34
    Screenshot from 2021-02-26 12-57-31

    (Also, as a quick note, I don't require this behavior for my library, just wanted to help @trusktr reporduce, since they had asked 😄 👍 )

  7. dcodeIO commented on Feb 26, 2021

    @dcodeIO
    Member

    @trusktr For some reason the second repro also doesn't work on my machine. Can't install glfw-raub or something.

    Btw, did you try if it works if you remove the /src/ from the import? I believe the root directory is dir(ascMain) essentially.

  8. trusktr commented on Feb 27, 2021

    @trusktr
    MemberAuthor

    @dcodeIO

    Yeah, I tried all approaches. @torch2424 listed one approach (direct file post-fixed onto the library name). But it fails on more approaches:

    // ascMain in some-lib is "src/index.js" which re-exports from "./path/to/direct/foo.ts"
    
    import {foo} from 'some-lib' // error
    import {foo} from 'some-lib/src/path/to/direct/foo.ts' // error
    
    // With this one I expect it to read `ascMain` from package.json in the `some-lib/` folder,
    // but I wouldn't be surprised if this particular case hasn't been implemented yet, as
    // people most likely won't be trying this unless they are working around the original issue.
    import {foo} from '../../../node_modules/some-lib' // error
    
    // This one works:
    import {foo} from '../../../node_modules/some-lib/src/path/to/direct/foo.ts' // good

    I didn't try to remove src/, but my guess is it won't work either.

    I'm in Linux. Maybe glfw-raub has an issue on another OS or flavor of Linux.

    Let me see about making a reproduction with only one dependency.

  9. p3nGu1nZz commented on Feb 28, 2021

    @p3nGu1nZz

    @trusktr For some reason the second repro also doesn't work on my machine. Can't install glfw-raub or something.

    Btw, did you try if it works if you remove the /src/ from the import? I believe the root directory is dir(ascMain) essentially.

    ruab doesnt work on my windows or linux machines either.

  10. JairusSW commented on Apr 1, 2021

    @JairusSW
    Member

    Got the same error... :(

  11. JairusSW commented on Apr 30, 2021

    @JairusSW
    Member

    Hey, @trusktr @torch2424 @ZoeDreams , it seems to be fixed!

  12. github-actions commented on Jun 2, 2021

    @github-actions

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed in one week if no further activity occurs. Thank you for your contributions!

  13. trusktr commented on Jul 6, 2021

    @trusktr
    MemberAuthor

    There's still an issue, so I continued in #1954

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions