rollup/rollup-plugin-node-resolve

'Unexpected token' from json file in aws-sdk when rolling up

bsommardahl opened this issue · 1 comments

I have a node 8 app that uses the aws-sdk package. When I run my build, rollup (0.43) throws the error you see below.

> rollup --config

Error: Unexpected token
node_modules/aws-sdk/lib/region_config_data.json (2:9)
1: {
2:   "rules": {
            ^
3:     "*/*": {
4:       "endpoint": "{service}.{region}.amazonaws.com"

I have not modified that json file in any way. I have tried removing node_modules and re-installing just in case I inadvertently messed something up in that package. Still the same error.

I found that, if I comment out all my AWS related code, it rolls up without error. If I even try to instantiate new AWS.SQS() and rollup, I get the same error. Here's my original code, which also doesn't work:

const incomingQueue = new AWS.SQS({
    credentials: awsConfig,
    endpoint: sqsConfig.incomingQueueUrl,
});

Here's my rollup config, in case it's relevant:

import sourcemaps from 'rollup-plugin-sourcemaps';
import nodeResolve from 'rollup-plugin-node-resolve';
import nodeGlobals from 'rollup-plugin-node-globals';
import nodeBuiltins from 'rollup-plugin-node-builtins';
import commonjs from 'rollup-plugin-commonjs';
import uglify from 'rollup-plugin-uglify';
import pascalCase from 'pascal-case';

const pkg = require('./package');

export default {
  moduleId: pkg.name,
  moduleName: pascalCase(pkg.name),
  entry: 'es/index.js',
  dest: 'dist/bundle.js',
  format: 'umd',
  exports: 'named',
  sourceMap: true,
  plugins: [
    sourcemaps(),
    nodeResolve(),
    nodeGlobals(),
    nodeBuiltins(),
    commonjs(),
    uglify()
  ]
};

IF I comment out nodeResolve() the error is replaced by the following warnings:

⚠️   'default' is imported from external module 'rollup-plugin-node-resolve' but never used

⚠️   options.moduleId is deprecated in favour of options.amd = { id: moduleId }

⚠️   'rxjs' is imported by es/dispatchers/SynchronousCommandDispatcher.js, but could not be resolved – treating it as an external dependency
https://github.com/rollup/rollup/wiki/Troubleshooting#treating-module-as-external-dependency

⚠️   'aws-sdk' is imported by es/index.js, but could not be resolved – treating it as an external dependency
https://github.com/rollup/rollup/wiki/Troubleshooting#treating-module-as-external-dependency

⚠️   'rxjs/Rx' is imported by es/index.js, but could not be resolved – treating it as an external dependency
https://github.com/rollup/rollup/wiki/Troubleshooting#treating-module-as-external-dependency

⚠️   No name was provided for external module 'rxjs' in options.globals – guessing 'Rx'

⚠️   No name was provided for external module 'aws-sdk' in options.globals – guessing 'AWS'

Hey @bsommardahl did you figure out how to resolve this?