0

I followed the sails.js documentation about using typescript in sails js app.

Not sure why, I get the following error:

error: A hook (`controllers`) failed to load!
error: `include-all` attempted to `require(project\api\controllers\MyController.js)`, but an error occurred::
Details:project\api\controllers\MyController.js:10
import util = require('util');
^^^^^^
SyntaxError: Unexpected token import

I'm using the same controller as given in the example in the using TypeScript page as mentioned above.

What could have gone wrong?

1
  • What version of Sails are you using? Commented May 22, 2017 at 3:31

1 Answer 1

1

I got the same error and it was because I was using "sails lift" and the documentation said to use "node app.js". Once I used the "node app.js" to start the application it worked as expected.

sails lift

info: Starting app...

error: A hook (`controllers`) failed to load!
error: `include-all` attempted to `require(/research/typeScriptPackage/testing/api/controllers/TsController.ts)`, but an error occurred::
Details:/research/typeScriptPackage/testing/api/controllers/TsController.ts:1
(function (exports, require, module, __filename, __dirname) { import util = require('util');

This was the step I missed:

"5. Start your app with node app.js instead of sails lift."

node app.js

info:
info:                .-..-.
info:
info:    Sails              <|    .-..-.
info:    v0.12.13            |\
info:                       /|.\
info:                      / || \
info:                    ,'  |'  \
info:                 .-'.-==|/_--'
info:                 `--'-------'
info:    __---___--___---___--___---___--___
info:  ____---___--___---___--___---___--___-__
info:
info: Server lifted in `/research/typeScriptPackage/testing`
info: To see your app, visit http://localhost:1337
info: To shut down Sails, press <CTRL> + C at any time.

debug: -------------------------------------------------------
debug: :: Fri Jul 14 2017 08:20:04 GMT-0700 (PDT)

debug: Environment : development
debug: Port        : 1337
debug: -------------------------------------------------------
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.