Question

I have one case where my imports were:

import docHeader = require('doc-header');
import listBody = require('list-body');

And failed saying they couldn't find the .js file and the url listed was missing document. So I changed them to:

import docHeader = require('document/doc-header');
import listBody = require('document/list-body');

The thing is, the file I have this in is in the document folder. Here's the file setup/call stack.

layout/worker-api.ts:

import document = require('document/document');
//...
var doc = new document.Document();
doc.deserialize(results.document);

layout/document/document.ts:

import docHeader = require('document/doc-header');
import listBody = require('document/list-body');
//...
export class Document {
    public guid : string;
    public docHeader : docHeader.DocHeader;
    public body : listBody.ListBody;

other files: layout/document/doc-header.ts layout/document/list-body.ts

Is it possible that because the call stack starts with worker-api.ts, that requireJS thinks that's the default directory? Everywhere else all of my imports work as expected. And it's definitely the folder it's in being required based on the error message.

Was it helpful?

Solution

Module names in RequireJS, unless explicitly pathed, are resolved relative to the base URL.

For example, if a script from http://example.com/foo/bar tries to load cat, the resolved URL will be http://example.com/cat.

You can resolve this by specifying a relative module name, like ./doc-header. TypeScript will also respect these relative paths.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top