rollup / rollup-plugin-commonjs

This module has moved and is now available at @rollup/plugin-commonjs / https://github.com/rollup/plugins/blob/master/packages/commonjs
MIT License
502 stars 126 forks source link

Module not exported (aws-sdk) #368

Closed Meemaw closed 4 years ago

Meemaw commented 5 years ago

Hello there! I am new to Rollup and would appreciate some help at setting up build for my common library written in Typescript. I managed to make build work for sometime but it stopped working at some point. I am getting the following error: [!] Error: 'DynamoDB' is not exported by node_modules/aws-sdk/lib/aws.js

My package.json looks like this:

{
  "name": "meshwatch-core",
  "version": "1.0.0",
  "main": "dist/meshwatch-core.umd.js",
  "module": "dist/meshwatch-core.es5.js",
  "typings": "dist/types/index.d.ts",
  "files": [
    "dist"
  ],
  "dependencies": {
    "aws-sdk": "^2.387.0",
    "boom": "^7.3.0",
    "joi": "^14.3.1",
    "node-fetch": "^2.3.0"
  },
  "scripts": {
    "test": "jest",
    "build": "tsc --module commonjs -p tsconfig.base.json && rollup -c rollup.config.ts && typedoc --out docs --target es6 --theme minimal --mode file src"
  },
  "devDependencies": {
    "@types/boom": "^7.2.1",
    "@types/jest": "^23.3.12",
    "@types/joi": "^14.0.1",
    "@types/node": "^10.12.18",
    "@types/node-fetch": "^2.1.4",
    "jest": "^23.6.0",
    "lodash.camelcase": "^4.3.0",
    "rollup": "^1.1.0",
    "rollup-plugin-commonjs": "^9.2.0",
    "rollup-plugin-json": "^3.1.0",
    "rollup-plugin-node-builtins": "^2.1.2",
    "rollup-plugin-node-resolve": "^4.0.0",
    "rollup-plugin-size-snapshot": "^0.8.0",
    "rollup-plugin-sourcemaps": "^0.4.2",
    "rollup-plugin-typescript2": "^0.18.1",
    "ts-jest": "^23.10.5",
    "typedoc": "^0.14.0",
    "typescript": "^3.2.2"
  }

And my rollup.config.ts like this:

import camelCase from 'lodash.camelcase';
import commonjs from 'rollup-plugin-commonjs';
import json from 'rollup-plugin-json';
import resolve from 'rollup-plugin-node-resolve';
import { sizeSnapshot } from 'rollup-plugin-size-snapshot';
import sourceMaps from 'rollup-plugin-sourcemaps';
import typescript from 'rollup-plugin-typescript2';

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

const input = 'src/index.ts';

const libraryName = 'meshwatch-core';

export default {
  input,
  output: [
    { file: pkg.main, name: camelCase(libraryName), format: 'umd', sourcemap: true },
    { file: pkg.module, format: 'es', sourcemap: true },
  ],
  external: [],
  watch: {
    include: 'src/**',
  },
  plugins: [
    // Allow json resolution
    json(),
    // Compile TypeScript files
    typescript({ useTsconfigDeclarationDir: true }),
    // Allow bundling cjs modules (unlike webpack, rollup doesn't understand cjs)
    commonjs(),
    // Allow node_modules resolution, so you can use 'external' to control
    // which external modules to include in the bundle
    // https://github.com/rollup/rollup-plugin-node-resolve#usage
    resolve({
      preferBuiltins: false,
    }),
    // Get size snapshot of the lib
    sizeSnapshot(),
    // Resolve source maps to the original source
    sourceMaps(),
  ],
};

I have tried following as suggested here, but without success:

commonjs({
      namedExports: {
        'node_modules/aws-sdk/clients/dynamodb.js': ['DynamoDB'],
      },
    })
Riim commented 4 years ago

Same problem: Error: 'snakeCaseAttributeName' is not exported by ../rionite-snake-case-attribute-name/dist/index.js Content of ../rionite-snake-case-attribute-name/dist/index.js :

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
let reCamelCase = /^_?[a-z][0-9a-z]*$/i;
let reLetters = /[A-Z][^A-Z]/g;
let reLetters2 = /[A-Z]{2,}/g;
let cache = new Map();
function snakeCaseAttributeName(str, useCache) {
    let value;
    return ((useCache && cache.get(str)) ||
        ((value = reCamelCase.test(str)
            ? str
                .replace(reLetters, word => '_' + word)
                .replace(reLetters2, word => '_' + word)
                .toLowerCase()
            : str),
            useCache && cache.set(str, value),
            value));
}
exports.snakeCaseAttributeName = snakeCaseAttributeName;

rollup.config.js :

import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import typescript from 'rollup-plugin-typescript2';

export default {
    input: './src/index.ts',

    output: {
        file: './dist/rionite.js',
        format: 'umd',
        name: 'rionite',

        globals: {
            '@riim/uid': '@riim/uid',
            cellx: 'cellx'
        }
    },

    external: [
        '@riim/uid',
        'cellx',
        'reflect-metadata'
    ],

    plugins: [
        nodeResolve({ browser: true }),
        commonjs({ include: /node_modules/ }),
        typescript({ clean: true })
    ]
};

No reaction to namedExports.

shellscape commented 4 years ago

Hey folks (this is a canned reply, but we mean it!). Thanks to everyone who participated in this issue. We're getting ready to move this plugin to a new home at https://github.com/rollup/plugins, and we have to do some spring cleaning of the issues to make that happen. We're going to close this one, but it doesn't mean that it's not still valid.

We've got some time yet before the move while we resolve pending Pull Requests, so if this issue is still relevant, please @ me and I'll make sure it gets reopened and transferred to the new repo. :beer: