rustyscreeps / cargo-screeps

Build tool for deploying Rust WASM code to Screeps game servers
MIT License
25 stars 13 forks source link

error: 'cargo web' generated unexpected JS prefix! #5

Closed ShaunKarran closed 5 years ago

ShaunKarran commented 5 years ago

Ran cargo screeps upload and hit this error.

First 30 lines of target/wasm32-unknown-unknown/release/screeps-starter-rust.js

"use strict";

if( typeof Rust === "undefined" ) {
    var Rust = {};
}

(function( root, factory ) {
    if( typeof define === "function" && define.amd ) {
        define( [], factory );
    } else if( typeof module === "object" && module.exports ) {
        module.exports = factory();
    } else {
        Rust.screeps_starter_rust = factory();
    }
}( this, function() {
    return (function( module_factory ) {
        var instance = module_factory();

        if( typeof window === "undefined" && typeof process === "object" ) {
            var fs = require( "fs" );
            var path = require( "path" );
            var wasm_path = path.join( __dirname, "screeps-starter-rust.wasm" );
            var buffer = fs.readFileSync( wasm_path );
            var mod = new WebAssembly.Module( buffer );
            var wasm_instance = new WebAssembly.Instance( mod, instance.imports );
            return instance.initialize( wasm_instance );
        } else {
            var file = fetch( "screeps-starter-rust.wasm", {credentials: "same-origin"} );

            var wasm_instance = ( typeof WebAssembly.instantiateStreaming === "function"
daboross commented 5 years ago

Sorry about this- I thought I'd replied! Apparently the reply got lost.

Generating files and cargo screeps works well for me with cargo-screeps version 0.2.0 and cargo-web version 0.6.19. Since this appears to be the latest format, I would guess your cargo-screeps build is outdated?

If cargo screeps --version and cargo web --version don't match the latest ones, you can use cargo install -f cargo-screeps and cargo install -f cargo-web to update each respectively.

If it is still erroring with the latest versions, let me know and I will see if I can think of any other reason this might be occurring.

ShaunKarran commented 5 years ago

I only just tried setting this up the other day so I assumed I already had the latest versions of everything.

I just tried using cargo install -f cargo-screeps and cargo install -f cargo-web and still got the same error. I do seem to have the same versions that you mentioned, cargo-screeps v0.2.0 and cargo-web v0.6.19.

daboross commented 5 years ago

Hm, darn. Something's up then! I'll try reinstalling everything I have as well to see if I can better replicate this...


Edit: ah yup. I fixed this in master (https://github.com/daboross/screeps-in-rust-via-wasm/commit/8169a20fe686e42361f600604e69caad10b9b48a) but completely forgot to publish a new cargo-screeps version.

I'll publish 0.2.1 with this shortly.

daboross commented 5 years ago

0.2.1 is now published! Should fix the issue- let me know if it's still a problem.

Sorry I hadn't fixed and published this earlier!

Nathanjp91 commented 5 years ago

Hey

I'm getting this same issue.

Just downloaded today, both seem to be up to date cargo-web 0.6.25 cargo-screeps 0.3.1

just attempting the screeps-starter-rust

Nathanjp91 commented 5 years ago
"use strict";

if( typeof Rust === "undefined" ) {
    var Rust = {};
}

(function( root, factory ) {
    if( typeof define === "function" && define.amd ) {
        define( [], factory );
    } else if( typeof module === "object" && module.exports ) {
        module.exports = factory();
    } else {
        Rust.screeps_starter_rust = factory();
    }
}( this, function() {
    return (function( module_factory ) {
        var instance = module_factory();

        if( typeof process === "object" && typeof process.versions === "object" && typeof process.versions.node === "string" ) {
            var fs = require( "fs" );
            var path = require( "path" );
            var wasm_path = path.join( __dirname, "screeps-starter-rust.wasm" );
            var buffer = fs.readFileSync( wasm_path );
            var mod = new WebAssembly.Module( buffer );
            var wasm_instance = new WebAssembly.Instance( mod, instance.imports );
            return instance.initialize( wasm_instance );
        } else {
            var file = fetch( "screeps-starter-rust.wasm", {credentials: "same-origin"} );

            var wasm_instance = ( typeof WebAssembly.instantiateStreaming === "function"
daboross commented 5 years ago

@NathanielPerkins Thanks for reminding me of this!

I think this is #140 - I'd merged a PR fixing the issue, but had not released it.

Just released the new version now, though. If you update to version 0.3.2, it should work correctly!

Nathanjp91 commented 5 years ago

Yep, updating to 0.3.2 worked. Just saw you've updated Crate.