question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`Error: 'Body' is not exported by ...` -- need to use `rollup-plugin-commonjs` to handle CJS files

See original GitHub issue

Here is my code:

import { Body } from 'cannon';
class CannonCollider extends Body {
    //....
}

Hints me that Error: 'Body' is not exported by node_modules\cannon\build\cannon.js

I have installed the cannon and @types/cannon.

Here is my tsconfig:

{
  "compilerOptions": {
    "target": "es6", 
    "module": "es6",
    "strict": true, 
    "moduleResolution": "node",
    "esModuleInterop": true,
  },
  // NO USE:
  // "include": [
  //   "@types/**/*.d.ts",
  //   "./**/*.d.ts",
  //   "./**/*.ts"
  // ],
  "exclude": [
    "node_modules",
  ]
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
shrinktofitcommented, Aug 15, 2018

Hey @ezolenko , I have resolved this problem by introducing commonjs plugin and do as following:

commonjs({
      namedExports: {
          'cannon': ['Body']
      }
    }

My rollup config:

module.exports = {
  input: './source/index.ts',
  external: [],
  plugins: [
    resolve({
      jsnext: true,
      main: true,
      root: process.cwd()
    }),
    commonjs({
      namedExports: {
        'cannon': ['Body']
      }
    }),
    typescript(),
  ],
  output: [
    {
      file: `${outDir}/${file}.dev.js`,
      format: 'iife',
      name,
      banner,
      globals,
      sourcemap,
    },
    {
      file: `${outDir}/${file}.js`,
      format: 'cjs',
      name,
      banner,
      globals,
      sourcemap,
    }
  ],
};
1reaction
ezolenkocommented, Aug 14, 2018

@shrinktofit could you post your rollup config?

Read more comments on GitHub >

github_iconTop Results From Across the Web

'name' is not exported by node_modules/... - even with explicit ...
I'm trying to use Rollup to bundle a test suite that uses tape. ... My configuration file is: import commonjs from 'rollup-plugin-commonjs'; ...
Read more >
Rollup Error: 'default' is not exported by node_modules/react ...
js but I have trouble regarding the plugin @rollup/plugin-commonjs. My rollup.conf.js. import resolve from '@rollup/plugin-node-resolve'; ...
Read more >
Introduction - rollup.js
Introduction. Overview. Rollup is a module bundler for JavaScript which compiles small pieces of code into something larger and more complex, ...
Read more >
rollup.js
If you want to write your configuration as a CommonJS module using require and module. exports , you should change the file extension...
Read more >
Bundling with Rollup - Vue.js 3 Course
commonjs (extension .cjs.js , for use with node.js) ... Add export default {} and run yarn rollup -c rollup.config.js . ... Error: Could...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found