Assemblyscript: Wrong paths for node modules with cli --sourceMap option

Created on 10 Sep 2019  路  2Comments  路  Source: AssemblyScript/assemblyscript

Problem:

When importing an AS node module, the paths for the sourceMaps are not generated correctly. The cli is looking for files in the ~lib/ folder of node_modules/assemblyscript/ instead of the node_modules/MODULE_NAME/ folder.

The generated paths are correct when using a relative import:
import { u128 } from "../node_modules/bignum/assembly/integer/u128"; :white_check_mark:
import { u128 } from "bignum"; :x:

How to recreate:

Create a new starter project & add bignum (or any other AS node module) as a dependency:

$ mkdir new-project && cd new-project
$ yarn add AssemblyScript/assemblyscript -D
$ npx asinit .
$ yarn add MaxGraey/bignum.wasm

And then import & use bignum in assembly/index.ts and compile the project

import { u128 } from "bignum";

export function add(): void {
  const test = u128.from<i32>(0);
}

$ yarn run asbuild:untouched

Which results in:

> asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --sourceMap --validate --debug

ERROR: Source file '~lib/bignum/utils.ts' not found.
    at sourceMap.sources.forEach (/Users/stefaniedoll/Parity/ParityJS/bignum-assemblyscript/node_modules/assemblyscript/cli/asc.js:723:31)
    at Array.forEach (<anonymous>)
    at Object.main (/Users/stefaniedoll/Parity/ParityJS/bignum-assemblyscript/node_modules/assemblyscript/cli/asc.js:707:29)
    at Object.<anonymous> (/Users/stefaniedoll/Parity/ParityJS/bignum-assemblyscript/node_modules/assemblyscript/bin/asc:21:26)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
ERROR: Source file '~lib/bignum/globals.ts' not found.
    at sourceMap.sources.forEach (/Users/stefaniedoll/Parity/ParityJS/bignum-assemblyscript/node_modules/assemblyscript/cli/asc.js:723:31)
    at Array.forEach (<anonymous>)
    at Object.main (/Users/stefaniedoll/Parity/ParityJS/bignum-assemblyscript/node_modules/assemblyscript/cli/asc.js:707:29)
    at Object.<anonymous> (/Users/stefaniedoll/Parity/ParityJS/bignum-assemblyscript/node_modules/assemblyscript/bin/asc:21:26)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
ERROR: Source file '~lib/bignum/integer/u128.ts' not found.
    at sourceMap.sources.forEach (/Users/stefaniedoll/Parity/ParityJS/bignum-assemblyscript/node_modules/assemblyscript/cli/asc.js:723:31)
    at Array.forEach (<anonymous>)
    at Object.main (/Users/stefaniedoll/Parity/ParityJS/bignum-assemblyscript/node_modules/assemblyscript/cli/asc.js:707:29)
    at Object.<anonymous> (/Users/stefaniedoll/Parity/ParityJS/bignum-assemblyscript/node_modules/assemblyscript/bin/asc:21:26)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
bug

Most helpful comment

The reason for this is that the resolver used by the parser isn't used when reading files for the sourcemap. However, it doesn't need to since all the sources have been read in by the parser. I'll make a PR that looks the files up internally instead of reading them again.

All 2 comments

The reason for this is that the resolver used by the parser isn't used when reading files for the sourcemap. However, it doesn't need to since all the sources have been read in by the parser. I'll make a PR that looks the files up internally instead of reading them again.

Thanks for taking care of it @willemneal and good to know that it doesn't have any effect! I guess just got triggered by the compiling errors and using relative imports for node modules just didn't really feel like a good "fix" to me.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vladimir-tikhonov picture vladimir-tikhonov  路  4Comments

MaxGraey picture MaxGraey  路  3Comments

andy-hanson picture andy-hanson  路  4Comments

solidsnail picture solidsnail  路  5Comments

torch2424 picture torch2424  路  3Comments