New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module import error while working with Rollup #73

Closed
fengshuo opened this Issue Mar 9, 2016 · 7 comments

Comments

Projects
None yet
2 participants
@fengshuo

fengshuo commented Mar 9, 2016

Hi,

I am using rollup to bundle i18next, i18next-xhr-backend, jquery-i18next with other ES6 modules, after rollup bundled these files successfully, browser logged an error message from i18next-xhr-backend/lib/index.js: utils.defaults is not a function.

I checked the source file, it seems that this line doesn't work as expected: var _utils = require('./utils'); , I tried to change it to non-relative paths: var _utils = require('utils');, then it works. I am not sure if it's caused by rollup plugins as described here, because no error message came from other packages (i18next, jquery-i18next), they are bundled in the same manner.

Below is the rollup config:

import babel from 'rollup-plugin-babel';
import commonjs from 'rollup-plugin-commonjs';
import includePaths from 'rollup-plugin-includepaths';
import nodeResolve from 'rollup-plugin-node-resolve';

var includePathOptions = {
  paths: ['es6'], //es6 folder is the main dev folder with es6 modules and libraries in node_modules
};

export default {
  entry: './es6/entry.js',
  plugins: [
    includePaths(includePathOptions),
    nodeResolve({
      jsnext: true,
      main: true,
      browser: true
    }),
    commonjs({
      include: './es6/node_modules/**'
    }),
    babel()
  ],
  format: 'amd',
  dest: 'build/bundle.js',
  sourceMap: true
};

Thanks

@jamuhl

This comment has been minimized.

Show comment
Hide comment
@jamuhl

jamuhl Mar 9, 2016

Member

hm...rather strange...can't say to much about it.

but stay tuned...working on building with rollup right now

so you can import from /dist/es or better said use the js:next entry

Member

jamuhl commented Mar 9, 2016

hm...rather strange...can't say to much about it.

but stay tuned...working on building with rollup right now

so you can import from /dist/es or better said use the js:next entry

@fengshuo

This comment has been minimized.

Show comment
Hide comment
@fengshuo

fengshuo Mar 10, 2016

Thanks for your quick response, can't wait to see the rollup version :)

fengshuo commented Mar 10, 2016

Thanks for your quick response, can't wait to see the rollup version :)

@jamuhl

This comment has been minimized.

Show comment
Hide comment
@jamuhl

jamuhl Mar 10, 2016

Member

all modules now have a jsnext:main in package.json leading to modules being babel transpiled and keeping module pattern. so they should be 'tree-shackable' by rollup

so there is now:
main -> commonjs build
jsnext:main -> es2015 build with modules

and for umd users /i18next(.min).js generated by rollup

Member

jamuhl commented Mar 10, 2016

all modules now have a jsnext:main in package.json leading to modules being babel transpiled and keeping module pattern. so they should be 'tree-shackable' by rollup

so there is now:
main -> commonjs build
jsnext:main -> es2015 build with modules

and for umd users /i18next(.min).js generated by rollup

@jamuhl

This comment has been minimized.

Show comment
Hide comment
@jamuhl

jamuhl Mar 10, 2016

Member

not sure doing the same here for i18next, i18next-xhr-backend, i18next-browser-languageDetector https://github.com/i18next/i18nextify/blob/master/rollup.config.js

only difference as i see is:

  • i still got old rollup-plugin-npm
  • i got no rollup-plugin-includepaths

but seems to work there...

Member

jamuhl commented Mar 10, 2016

not sure doing the same here for i18next, i18next-xhr-backend, i18next-browser-languageDetector https://github.com/i18next/i18nextify/blob/master/rollup.config.js

only difference as i see is:

  • i still got old rollup-plugin-npm
  • i got no rollup-plugin-includepaths

but seems to work there...

@fengshuo

This comment has been minimized.

Show comment
Hide comment
@fengshuo

fengshuo Mar 11, 2016

It seems to be a plugin issue, probably the rollup-plugin-includepaths? What's odd is, I tried to uninstall and reinstall npm packages with some minor changes in rollup.config.js(and more include paths in includepathOptions, I don't think this would affect npm packages though), the error in browser this time is '18next-xhr-backend doesn't export default...', so I change the relative path again then it works....

I'll try your rollup.config.js later and see if it works.

fengshuo commented Mar 11, 2016

It seems to be a plugin issue, probably the rollup-plugin-includepaths? What's odd is, I tried to uninstall and reinstall npm packages with some minor changes in rollup.config.js(and more include paths in includepathOptions, I don't think this would affect npm packages though), the error in browser this time is '18next-xhr-backend doesn't export default...', so I change the relative path again then it works....

I'll try your rollup.config.js later and see if it works.

@jamuhl

This comment has been minimized.

Show comment
Hide comment
@jamuhl

jamuhl Mar 11, 2016

Member

build chains this days didn't get easier...sometimes i wish i never changed to use babel and co.

Member

jamuhl commented Mar 11, 2016

build chains this days didn't get easier...sometimes i wish i never changed to use babel and co.

@jamuhl

This comment has been minimized.

Show comment
Hide comment
@jamuhl

jamuhl Jul 25, 2016

Member

closing for now...feel free to reopen.

Member

jamuhl commented Jul 25, 2016

closing for now...feel free to reopen.

@jamuhl jamuhl closed this Jul 25, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment