简体   繁体   中英

Typescript App not looking in node_modules folder

When I load the app from the root directory of my server the app works. This is not possible in practice because of the pretty urls our application uses. For example http://www.website.com/modules/worker/person/1/1/1 loading a page with the previous url results in system.js looking in the folder /modules/worker/person/1/1 rather than a folder based on "/".

The solution is to set baseURL:"/" such that the modules are loaded based on the root directory.

The problem with THIS solution is that node modules are not loaded properly, instead of looking in the node_modules directory, system.js is looking in the root. system.js looks in /angular2/http.js rather than /node_modules/angular2/http.js

When I switch from "node" module compilation to "classic" the result is the same.

Any thoughts on how to proceed?

Here was my solution to this problem using the paths property in the System.config object:

    System.config({
        defaultJSExtensions: true,
        baseURL: "/",
        paths: {
            'modules/worker/*': '/modules/worker/*',
            'angular2/*': '/node_modules/angular2/*',
            'rxjs/*': '/node_modules/rxjs/*',
        },
        packages: {
            modules : {
                worker: {
                    format: 'register',
                    defaultExtension: 'js'
                }
            }
        }
    });
    System.import('modules/worker/main')
            .then(null, console.error.bind(console));

For each asset that was being loaded outside main.js (all external libraries) I had to directly point to them in the paths config property. This list would be different depending on the dependencies of your published Typescript classes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM