auth0 / wt-cli

Webtask CLI - all you need is code
https://webtask.io
MIT License
322 stars 72 forks source link

Bundler is not resolving peer dependencies #127

Open rohit-ravikoti opened 7 years ago

rohit-ravikoti commented 7 years ago

When using lokka with lokka-transport-http:

Rohits-Air:activation-code-generator-wt rohitravikoti$ wt create index.js --bundle
* Hint: If you would like to opt-out from this behaviour, pass in the --ignore-package-json flag.
Resolving 3 modules...
Provisioning 3 modules...
lokka@1.7.0 is available
lokka-transport-http@1.6.1 is available
voucher-code-generator@1.1.1 is available
Webtask created
​
You can access your webtask at the following url:
​
https://wt-6d6ba479746756b8590f0b6221de0b05-0.run.webtask.io/activation-code-generator
​
Error I get when I follow the URL:
​
{
  "code": 400,
  "message": "Compilation failed: Cannot find module 'lokka/transport'",
  "error": "Cannot find module 'lokka/transport'",
  "stack": "Error: Cannot find module 'lokka/transport'\n    at Function.Module._resolveFilename (module.js:325:15)\n    at Function.Module._load (module.js:276:25)\n    at Module.require (module.js:353:17)\n    at require (internal/module.js:12:17)\n    at Object.<anonymous> (/data/_verquire/lokka-transport-http/1.6.1/node_modules/lokka-transport-http/dist/index.js:40:18)\n    at Module._compile (module.js:409:26)\n    at Object.Module._extensions..js (module.js:416:10)\n    at Module.load (module.js:343:32)\n    at Function.Module._load (module.js:300:12)\n    at Module.require (module.js:353:17)\n    at require (internal/module.js:12:17)"
}
heymartinadams commented 6 years ago

Same here.

wt create http://code.affiliategenius.com/webtask.js --name AffiliateGenius --secret privateKey=__PRIVATE_KEY__ --parse-body --meta 'wt-node-dependencies'='{"affiliategenius-test":"1.0.15"}'

Result:

Resolving 1 module...
Provisioning 1 module...
affiliategenius-test@1.0.15 is available
Webtask created

You can access your webtask at the following url:

https://wt-607887792589a1d1a518ce2c83b6dddd-0.run.webtask.io/AffiliateGenius

As you can see below, from the http://code.affiliategenius.com/webtask.js file (update: no longer available), it requires a simple npm package that’s dynamically loaded via the --meta tag:

'use latest'
var AffiliateGenius = require('affiliategenius-test@1.0.15')
module.exports = (context, callback) => AffiliateGenius(context, callback)

Yet the resulting webtask says it’s not available:

Compilation failed: Cannot find module 'affiliategenius-test@1.0.15'
heymartinadams commented 6 years ago

It appears that my above-referenced issue only shows up for code located on a website (in my case, http://code.affiliategenius.com/webtask.js). Modules are properly loaded if a webtask is created using a local file instead:

wt create ./webtask.js --name AffiliateGenius --secret privateKey=__PRIVATE_KEY__ --parse-body --meta 'wt-node-dependencies'='{"affiliategenius-test":"1.0.15"}'

Your above example, @rohit-ravikoti, is from a local file, so it looks like my issue is not related.

Recommended Action: I would recommend the Webtask team add a reminder to the module chapter in docs that webtasks cannot load dependencies if web-based code is being used.