[Solved] Import es6 with nodejs

Hi,

I’m trying to use the sdk with nodejs but I’m having problems with imports. I’m using webpack, but when try to execute a method of the sdk, I get an error:

node_modules/@aeternity/aepp-sdk/es/ae/universal.js:25
import Ae from './'
^^^^^^

SyntaxError: Unexpected token import

This is my configuration in webpack

const path = require(‘path’)
const nodeExternals = require(‘webpack-node-externals’)
const nodeModules = require(‘webpack-node-modules’)

module.exports = {
    mode: 'development',
    target: 'node',
    entry: {
        app: path.resolve(__dirname, 'src', 'index.js'),
    },
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'index.js',
    },
    externals: [nodeExternals()],
    module: {
        rules: [
            {
              test: /\.js$/,
              loader: 'babel-loader',
              include: [
                path.join(__dirname, 'src'),
                nodeModules()
              ]
            },
            {
                test: /\.aes$/,
                loader: 'ignore-loader'
              }
          ]
    }
};

And when I do buid, is being build

Hash: 92b0da248df3318c41e3
Version: webpack 4.41.5
Time: 396ms
Built at: 2020-01-09 23:03:56
Asset Size Chunks Chunk Names
index.js 11.3 KiB app [emitted] app
Entrypoint app = index.js
[./src/index.js] 68 bytes {app} [built]
[./src/utils/aeternity.js] 2.92 KiB {app} [built]
[./src/utils/util.js] 265 bytes {app} [built]
[@aeternity/aepp-sdk/] external “@aeternity/aepp-sdk/” 42 bytes {app} [built]
[@aeternity/aepp-sdk/es/ae/universal] external “@aeternity/aepp-sdk/es/ae/universal” 42 bytes {app} [built]
[bignumber.js] external “bignumber.js” 42 bytes {app} [built]

But when I try to run the code I got an error. I’m using this field of the of the boilerplate to connect with the sdk

Do I need to change anything on webpack?

Thanls

Usage from nodejs will not work using import syntax, here is an example using require https://github.com/aeternity/aepp-sdk-js/blob/develop/docs/guides/import-nodejs.md

1 Like

Thanks @philipp.chain! I tried with that and it is working now

1 Like