Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
trusktr opened this issue Feb 9, 2021 · 13 comments
Closed

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

trusktr opened this issue Feb 9, 2021 · 13 comments
Labels

Comments

@trusktr
Copy link
Member

trusktr commented Feb 9, 2021

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)
@p3nGu1nZz
Copy link

p3nGu1nZz commented Feb 13, 2021

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'

@dcodeIO
Copy link
Member

dcodeIO commented Feb 14, 2021

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.

@trusktr
Copy link
Member Author

trusktr commented Feb 14, 2021

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.

@trusktr
Copy link
Member Author

trusktr commented Feb 23, 2021

@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)

@trusktr
Copy link
Member Author

trusktr commented Feb 23, 2021

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

@torch2424
Copy link
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 😄 👍 )

@dcodeIO
Copy link
Member

dcodeIO commented Feb 26, 2021

@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.

@trusktr
Copy link
Member Author

trusktr commented Feb 27, 2021

@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.

@p3nGu1nZz
Copy link

@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.

trusktr added a commit to lume/ASWebGLue that referenced this issue Feb 28, 2021
…dates

* 'interop-with-node' of github.com:lume/ASWebGLue:
  Use direct file path until AssemblyScript module resolution is fixed (AssemblyScript/assemblyscript#1679)
  add Node.js example (WIP, something broke)
  changes for use in Node with webgl-raub
@JairusSW
Copy link
Contributor

JairusSW commented Apr 1, 2021

Got the same error... :(

@JairusSW
Copy link
Contributor

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

@github-actions
Copy link

github-actions bot commented Jun 2, 2021

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!

@trusktr
Copy link
Member Author

trusktr commented Jul 6, 2021

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
Labels
Projects
None yet
Development

No branches or pull requests

5 participants