为什么我收到以下错误:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [ "es2015", "dom" ],
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
}
}
在Firefox 36中收到了这样的错误,在移动浏览器中它只是无法加载,尽管在移动版Firefox中都加载了。
tsconfig.json
(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
'app': 'app',
// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platf$
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynam$
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
// other libraries
'rxjs': 'npm:rxjs',
'underscore': 'npm:underscore/underscore.js',
'socket.io-client': 'node_modules/socket.io-client/dist/socket.io.js',
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-me$
},
// packages tells the System loader how to load when no filename and/or no $
packages: {
app: {
defaultExtension: 'js',
meta: {
'./*.js': {
loader: 'systemjs-angular-loader.js'
}
}
},
rxjs: {
defaultExtension: 'js'
},
"socket.io-client": {
"defaultExtension": "js"
}
}
});
})(this);
还尝试使用es6-shim,es6-promise
进行编译systemjs.config.js
var templateUrlRegex = /templateUrl\s*:(\s*['"`](.*?)['"`]\s*)/gm;
var stylesRegex = /styleUrls *:(\s*\[[^\]]*?\])/g;
var stringRegex = /(['`"])((?:[^\\]\\\1|.)*?)\1/g;
module.exports.translate = function(load){
var url = document.createElement('a');
url.href = load.address;
var basePathParts = url.pathname.split('/');
basePathParts.pop();
var basePath = basePathParts.join('/');
var baseHref = document.createElement('a');
baseHref.href = this.baseURL;
baseHref = baseHref.pathname;
basePath = basePath.replace(baseHref, '');
load.source = load.source
.replace(templateUrlRegex, function(match, quote, url){
let resolvedUrl = url;
if (url.startsWith('.')) {
resolvedUrl = basePath + url.substr(1);
}
return 'templateUrl: "' + resolvedUrl + '"';
})
.replace(stylesRegex, function(match, relativeUrls) {
var urls = [];
while ((match = stringRegex.exec(relativeUrls)) !== null) {
if (match[2].startsWith('.')) {
urls.push('"' + basePath + match[2].substr(1) + '"');
} else {
urls.push('"' + match[2] + '"');
}
}
return "styleUrls: [" + urls.join(', ') + "]";
});
return load;
};
systemjs-角loader.js
@ApplicationPath("webapi")
public class MyApplication extends Application {
}
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("pet")
public class PetResource {
@GET
@Path("/{breed}/{name}")
@Produces(MediaType.TEXT_PLAIN)
public Pet getPet(@PathParam("breed") String breed, @PathParam("name") String name) {
return new Pet(breed, name);
}
}
import java.io.IOException;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;
@Provider
@Produces(MediaType.TEXT_PLAIN)
public class CustomMessageBodyWriter implements MessageBodyWriter<Pet> {
@Override
public long getSize(Pet arg0, Class<?> arg1, Type arg2, Annotation[] arg3,
MediaType arg4) {
return -1;
}
@Override
public boolean isWriteable(Class<?> type, Type arg1, Annotation[] arg2,
MediaType arg3) {
return Pet.class.isAssignableFrom(type);
}
@Override
public void writeTo(Pet pet, Class<?> type, Type arg2, Annotation[] arg3,
MediaType arg4, MultivaluedMap<String, Object> arg5,
OutputStream out) throws IOException, WebApplicationException {
out.write(pet.toString().getBytes());
}
}
public class Pet {
private String name;
private String breed;
public Pet() {
}
public Pet(String breed, String name) {
this.name = name;
this.breed = breed;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getBreed() {
return breed;
}
public void setBreed(String breed) {
this.breed = breed;
}
@Override
public String toString() {
return "Pet [name=" + name + ", breed=" + breed + "]";
}
}