surma / rollup-plugin-assemblyscript

A Rollup plugin that allows you to import AssemblyScript files and compiles them on-the-fly.
https://npm.im/rollup-plugin-assemblyscript
Apache License 2.0
74 stars 9 forks source link

Could not load asc:{path to file}/file.as #2

Closed andyricchuiti closed 4 years ago

andyricchuiti commented 4 years ago

I'm super excited to try out assemblyscript in a project. thanks for building this plugin!

when i used this plugin to try the add example, I keep getting:

[!] (plugin assemblyscript) Error: Could not load asc:/correct/path/to/file/file.as (imported by file/using/this/import/service.js)

In the file.as I have

export function add(a: i32, b: i32): i32 {
  return a + b;
}

in the service.js i have:

import {instancePromise} from 'asc:./file.as';
class Service{
  ...
  async doAdd(a, b) {
    const instance = await instancePromise;
    return instance.exports.add(a, b);
  }
}

The only thing that I'm not sure about is that I'm using @open-wc's rollup config, so my rollup config looks like:

import {createSpaConfig} from '@open-wc/building-rollup';
import gzipPlugin from 'rollup-plugin-gzip'
import { asc } from "rollup-plugin-assemblyscript";

const config = createSpaConfig({ legacyBuild: false, injectServiceWorker: false });

export default {
  ...config,
  input: './src/index.html',
  plugins: [
    asc(),
    ...config.plugins,
    gzipPlugin({
      filter: /\.(js|mjs|json|css)$/
    }),
  ],
}

I guess my main question is, am I missing something obvious on the plugin side of things?

Once again, thank you for building the plugin!

surma commented 4 years ago

Currently on vacation, but if you put a sample into a gist or a GitHub repository, I'll take a look when I'm back next week :)

andyricchuiti commented 4 years ago

nice! i hope it goes well (or was good).

so. i have a repo, but while setting it up, i realized the problem was with me using .as instead of .ts I went ahead and uploaded the repo with the .as if you still wanted to see it. https://github.com/andyricchuiti/as-test.

but if you change the file type to .ts everything works great and is seemless! my guess is the compiler is now strict with the file type?

surma commented 4 years ago

Yeah, that is the AssemblyScript compiler enforcing .ts extension I think. Glad you figured it out :)

munrocket commented 3 years ago

It has but this flag in another format, --extension .as instead of --extension=.as. Plugin enforcing the old version of AS even if you installed a new one. I created a quick fix for .as support #3 and updated version of AS but should we allow to pass any string to compiler and take AS that stored in your current repo? I can fix this but I don't have any feedback right now.