Closed sbrl closed 4 years ago
Thanks for reporting.
You mean this is wrong?
Huh, that looks completely different to what I'm seeing in the package I've installed from npm, @johanstokking! Here's what I'm seeing: index.js.log (renamed to .log so that GitHub accepts it)
Specifically, this:
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.account = exports.data = exports.application = exports.services = exports.Discovery = exports.ApplicationClient = exports.wildcard = exports.DataClient = exports.key = exports.HandlerClient = undefined;
....
var data = exports.data = function () {
var _ref3 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3(appID, accessKeyOrToken, opts) {
var handler;
.....
Hmm 🤔 the published version may be transpiled weirdly.
What if you clone this repo and reference locally?
If you have ideas to fix this, that would be very much welcomed.
@johanstokking After cloning it to a subfolder inside node_modules
and running the following test program:
"use strict";
import { data } from './node_modules/node-app-sdk/src/index.js';
console.log(data);
....I get this error:
$ node --experimental-modules index.mjs
(node:7124) ExperimentalWarning: The ESM module loader is experimental.
file:///tmp/test/index.mjs:1
import { data } from './node_modules/node-app-sdk/src/index.js';
^^^^
SyntaxError: The requested module './node_modules/node-app-sdk/src/index.js' does not provide an export named 'data'
at ModuleJob._instantiate (internal/modules/esm/module_job.js:93:21)
at async ModuleJob.run (internal/modules/esm/module_job.js:108:20)
at async Loader.import (internal/modules/esm/loader.js:134:24)
For reference, I'm attempting to import src/index.js.
If I change the above test script to import the default export instead, I get this error:
$ node --experimental-modules index.mjs
(node:8388) ExperimentalWarning: The ESM module loader is experimental.
/tmp/test/node_modules/node-app-sdk/src/index.js:6
import { HandlerClient } from "./handler"
^
SyntaxError: Unexpected token {
at Module._compile (internal/modules/cjs/loader.js:720:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at internal/modules/esm/translators.js:87:15
at Object.meta.done (internal/modules/esm/create_dynamic_module.js:48:9)
at file:///tmp/test/node_modules/node-app-sdk/src/index.js:9:13
at ModuleJob.run (internal/modules/esm/module_job.js:111:37)
at async Loader.import (internal/modules/esm/loader.js:134:24)
....I'm confused.
Instead of "import", use const and require.
const { data, application } = require('ttn');
In theory that would work around the issue @Minyanaing, the but specific problem here is that it doesn't work with es6 modules - i.e. the import
export
syntax.
@Minyanaing @sbrl can you make a PR?
Currently if I use this package with Node.js, I get the following error:
I'm executing my program like this:
node --experimental-modules ./server/index.mjs
....I think there's a packaging error. Inspecting
index.js
reveals that it's using some customexports
variable, and not an ES6export { example_function };
statement as it should be, or even a legacymodule.exports = { /* ..... */ };
- hence Node.js doesn't recognise it.Edit: Oh yeah, here are my software version details: