Fp-ts: es6 version is broken

Created on 23 Sep 2019  路  5Comments  路  Source: gcanti/fp-ts

The lib should work out of the box imho. I am using default Next.js configuration.

node_modules/fp-ts/es6/pipeable.js:1
import { identity } from './function';
       ^

SyntaxError: Unexpected token {
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)

Importing from /lib ofc works.

Most helpful comment

With Next.js I'm using the following additional loader to handle ES6 modules.

// next.config.js
module.exports = {
  webpack: (config, { defaultLoaders }) => {
    config.module.rules.push({
      test: /\.(js|jsx)$/,
      loader: defaultLoaders.babel,
      include: [/node_modules\/d3-.+/, /node_modules\/.+-ts\/es6\/.+/]
    });
  })
}

As there are _so many_ ways to configure JS compilation these days, I'm not sure this is an fp-ts specific problem; as you can see in my config, I'm also registering d3 modules for transpilation, as they come as ES6 as well.

All 5 comments

Experienced the same with NodeJS

With Next.js I'm using the following additional loader to handle ES6 modules.

// next.config.js
module.exports = {
  webpack: (config, { defaultLoaders }) => {
    config.module.rules.push({
      test: /\.(js|jsx)$/,
      loader: defaultLoaders.babel,
      include: [/node_modules\/d3-.+/, /node_modules\/.+-ts\/es6\/.+/]
    });
  })
}

As there are _so many_ ways to configure JS compilation these days, I'm not sure this is an fp-ts specific problem; as you can see in my config, I'm also registering d3 modules for transpilation, as they come as ES6 as well.

As @grossbart says, there are ways already to import the es6 version from Next (or to use the transpiled version from /lib).

I think fp-ts already stands above the average npm package in providing both versions out of the box :) Closing this

@giogonzo You were right. The fix for my case was surprisingly simple:

module.exports = withBundleAnalyzer(
  withTranspileModules({
    // To force Next.js to transpile code from other workspace packages.
    // https://github.com/martpie/next-transpile-modules
    transpileModules: ['slad', 'fp-ts'],
  }),
);

As I checked it manually, the code is properly tree shaked.

I鈥檝e tried many different combinations of this but I just cannot get this to work 馃槶 We鈥檙e transpiling some other packages already so I don鈥檛 understand what鈥檚 going on. It鈥檚 super weird because if I change the import to fp-ts/es6/... in one file this works fine, but it seems to not work for a few other files. Anyone run into anything similar?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vicrac picture vicrac  路  4Comments

amaurymartiny picture amaurymartiny  路  4Comments

miguelferraro picture miguelferraro  路  3Comments

mmkal picture mmkal  路  3Comments

steida picture steida  路  4Comments