fluentui icon indicating copy to clipboard operation
fluentui copied to clipboard

fluentui 8 compatibility issues with Next 10

Open DZFLUX opened this issue 5 years ago • 10 comments

Environment Information

"@fluentui/react": "^8.5.0",
"@fluentui/react-theme-provider": "^0.18.5",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"@types/jest": "^26.0.15",
"@types/node": "^12.0.0",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"next": "^10.1.3",
"office-ui-fabric-react": "^7.165.2",    

Describe the issue:

Usage of 'office-ui-fabric-react/lib/Dropdown' fails in next 10 environments.

Actual behavior:

import { Dropdown, DropdownMenuItemType, IDropdownStyles, IDropdownOption } from 'office-ui-fabric-react/lib/Dropdown';
/Users/chad/Documents/git/FUI/fluent-ui-app/bm-marketplace/node_modules/office-ui-fabric-react/lib/Dropdown.js:1
export * from './components/Dropdown/index';
^^^^^^

SyntaxError: Unexpected token 'export'
    at wrapSafe (internal/modules/cjs/loader.js:931:16)
    at Module._compile (internal/modules/cjs/loader.js:979:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
    at Module.load (internal/modules/cjs/loader.js:879:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Module.require (internal/modules/cjs/loader.js:903:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at eval (webpack-internal:///office-ui-fabric-react/lib/Dropdown:1:18)

Expected behavior:

working import of Dropdown interfaces/classes.

If applicable, please provide a codepen repro:

environment setup: npx create-react-app bm-marketplace --template typescript cd bm-marketplace yarn add @fluentui/react @fluentui/react-theme-provider yarn add office-ui-fabric-react This isn't needed in a regular react project, but tried in troubleshooting yarn add next react react-dom

Edit index.tsx to contain "import { Dropdown, DropdownMenuItemType, IDropdownStyles, IDropdownOption } from 'office-ui-fabric-react/lib/Dropdown';"

Priorities and help requested (not applicable if asking question):

Are you willing to submit a PR to fix? (Yes, No) No clue how to resolve.

Requested priority: (Blocking, High, Normal, Low) I assume Normal, would be nice to get initial response if FluentUI is designed to work with NextJS or not. I see another issue for this months ago that was auto-closed to submitter not responding to comments.

Products/sites affected: (if applicable)

DZFLUX avatar Apr 04 '21 03:04 DZFLUX

It looks like something in your setup isn't handling ES Module syntax. Without seeing more details, it's hard to say exactly which part is the issue. Can you try forking and editing this codesandbox to repro the issue? https://codesandbox.io/s/issue-17695-vc3k1

Also, you shouldn't be using office-ui-fabric-react and @fluentui/react@8 together, since that will give you a huge amount of duplicated code. New apps should be using @fluentui/react only.

ecraig12345 avatar Apr 08 '21 02:04 ecraig12345

It looks like something in your setup isn't handling ES Module syntax. Without seeing more details, it's hard to say exactly which part is the issue. Can you try forking and editing this codesandbox to repro the issue? https://codesandbox.io/s/issue-17695-vc3k1

Also, you shouldn't be using office-ui-fabric-react and @fluentui/react@8 together, since that will give you a huge amount of duplicated code. New apps should be using @fluentui/react only.

I will test with that repo. Perhaps we can add some guidance to the fluentui samples at https://developer.microsoft.com/en-us/fluentui#/ to make that point clear.

DZFLUX avatar Apr 08 '21 11:04 DZFLUX

I tested this codesandbox and it's failing for me (locally, oncodesandbox, and on vercel). codesandbox SyntaxError: Could not fetch dependencies, please try again in a couple seconds: Unexpected token < in JSON at position 0 locally

$ react-scripts start
/Users/chad/Downloads/issue-17695-forked/node_modules/react-scripts/scripts/utils/verifyTypeScriptSetup.js:231
        appTsConfig.compilerOptions[option] = suggested;
                                            ^

TypeError: Cannot add property target, object is not extensible
    at verifyTypeScriptSetup (/Users/chad/Downloads/issue-17695-forked/node_modules/react-scripts/scripts/utils/verifyTypeScriptSetup.js:231:45)
    at Object.<anonymous> (/Users/chad/Downloads/issue-17695-forked/node_modules/react-scripts/scripts/start.js:31:1)
    at Module._compile (internal/modules/cjs/loader.js:1015:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
    at Module.load (internal/modules/cjs/loader.js:879:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    at internal/main/run_main_module.js:17:47
error Command failed with exit code 1.

**vercel**
16:17:45.111 | $ react-scripts build
-- | --
16:17:45.530 | /vercel/path0/node_modules/react-scripts/scripts/utils/verifyTypeScriptSetup.js:231
16:17:45.530 | appTsConfig.compilerOptions[option] = suggested;
16:17:45.530 | ^
16:17:45.531 | TypeError: Cannot add property target, object is not extensible
16:17:45.531 | at verifyTypeScriptSetup (/vercel/path0/node_modules/react-scripts/scripts/utils/verifyTypeScriptSetup.js:231:45)
16:17:45.531 | at Object.<anonymous> (/vercel/path0/node_modules/react-scripts/scripts/build.js:31:1)
16:17:45.531 | at Module._compile (internal/modules/cjs/loader.js:1063:30)
16:17:45.531 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
16:17:45.531 | at Module.load (internal/modules/cjs/loader.js:928:32)
16:17:45.531 | at Function.Module._load (internal/modules/cjs/loader.js:769:14)
16:17:45.531 | at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
16:17:45.531 | at internal/main/run_main_module.js:17:47
16:17:45.544 | error Command failed with exit code 1.
16:17:45.545 | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
16:17:45.562 | Error: Command "yarn run build" exited with 1



16:17:45.111 | $ react-scripts build
-- | --
16:17:45.530 | /vercel/path0/node_modules/react-scripts/scripts/utils/verifyTypeScriptSetup.js:231
16:17:45.530 | appTsConfig.compilerOptions[option] = suggested;
16:17:45.530 | ^
16:17:45.531 | TypeError: Cannot add property target, object is not extensible
16:17:45.531 | at verifyTypeScriptSetup (/vercel/path0/node_modules/react-scripts/scripts/utils/verifyTypeScriptSetup.js:231:45)
16:17:45.531 | at Object.<anonymous> (/vercel/path0/node_modules/react-scripts/scripts/build.js:31:1)
16:17:45.531 | at Module._compile (internal/modules/cjs/loader.js:1063:30)
16:17:45.531 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
16:17:45.531 | at Module.load (internal/modules/cjs/loader.js:928:32)
16:17:45.531 | at Function.Module._load (internal/modules/cjs/loader.js:769:14)
16:17:45.531 | at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
16:17:45.531 | at internal/main/run_main_module.js:17:47
16:17:45.544 | error Command failed with exit code 1.
16:17:45.545 | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
16:17:45.562 | Error: Command "yarn run build" exited with 1




16:17:45.111 | $ react-scripts build
-- | --
16:17:45.530 | /vercel/path0/node_modules/react-scripts/scripts/utils/verifyTypeScriptSetup.js:231
16:17:45.530 | appTsConfig.compilerOptions[option] = suggested;
16:17:45.530 | ^
16:17:45.531 | TypeError: Cannot add property target, object is not extensible
16:17:45.531 | at verifyTypeScriptSetup (/vercel/path0/node_modules/react-scripts/scripts/utils/verifyTypeScriptSetup.js:231:45)
16:17:45.531 | at Object.<anonymous> (/vercel/path0/node_modules/react-scripts/scripts/build.js:31:1)
16:17:45.531 | at Module._compile (internal/modules/cjs/loader.js:1063:30)
16:17:45.531 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
16:17:45.531 | at Module.load (internal/modules/cjs/loader.js:928:32)
16:17:45.531 | at Function.Module._load (internal/modules/cjs/loader.js:769:14)
16:17:45.531 | at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
16:17:45.531 | at internal/main/run_main_module.js:17:47
16:17:45.544 | error Command failed with exit code 1.
16:17:45.545 | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
16:17:45.562 | Error: Command "yarn run build" exited with 1

DZFLUX avatar Apr 08 '21 20:04 DZFLUX

What I meant was that you should fork the codesandbox (within the codesandbox web UI) and make modifications there to resemble your setup, not try to download it locally.

ecraig12345 avatar Apr 08 '21 20:04 ecraig12345

Hi Elizabeth, I got the intent to use codesandbox to more clearly demonstrate the issue, but when using codesandbox to try to spin up that code it fails (prior to forking it and making any changes on my side). See link below. (https://u.pcloud.link/publink/show?code=XZ61JsXZmuG7Apj9UfYgYnOwSYfnG4iK7Rgk)]

DZFLUX avatar Apr 08 '21 22:04 DZFLUX

@DayZeroLLC - thanks for sharing the code sandbox url .

@miroslavstastny - Would you be able to confirm if this is a regression, or if this behavior is an issue? cc @ecraig12345

gouttierre avatar Jun 07 '21 13:06 gouttierre

I see the same problem in both v7 and v8. Next v10 compilation fails whenever deep imports are used:

export * from './components/Dropdown/index';
^^^^^^

SyntaxError: Unexpected token 'export'

But that's what docs recommend: https://github.com/microsoft/fluentui/wiki/Server-side-rendering-and-browserless-testing.

I propose to update the documentation to import directly from office-ui-fabric-react (v7) or @fluentui/react (v8) - tested that in that case it Next.js works as expected. @ecraig12345, @layershifter would you agree?

miroslavstastny avatar Jun 25 '21 20:06 miroslavstastny

Deep imports are not compatible with Next.js because Next.js will run code in Node environment for SSR while /lib/**/* files contain only ESM. I see multiple options to solve "deep imports" problem:

Option 1

Is to configure something like babel-plugin-transform-imports directly on Webpack loader in next.config.js: it will transform normal imports to deep ones but I never tried such setup.

Option 2

Use next-transpile-modules, it should work out of the box:

code transpilation from NPM modules using ES6 imports (e.g lodash-es)

Can you please try it @miroslavstastny?

layershifter avatar Jun 28 '21 10:06 layershifter

I have met the same SyntaxError export... issue with next.js 11 and fluentui/react 8 while following fluentui demos.

/home/lijian/Code/metaphor/frontend/fluentui-demo/node_modules/@fluentui/react/lib/Stack.js:1
export * from './components/Stack/index';
^^^^^^

SyntaxError: Unexpected token 'export'
    at wrapSafe (internal/modules/cjs/loader.js:979:16)
    at Module._compile (internal/modules/cjs/loader.js:1027:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.@fluentui/react/lib/Stack (/home/lijian/Code/metaphor/frontend/fluentui-demo/.next/server/pages/stack/basic.js:33:18)
    at __webpack_require__ (/home/lijian/Code/metaphor/frontend/fluentui-demo/.next/server/webpack-runtime.js:33:42)
    at eval (webpack-internal:///./pages/stack/basic.tsx:6:83)

The fluentui/react demo code from documentation site has imports like the following:

import * as React from 'react';
import { Stack, IStackStyles, IStackTokens, IStackItemStyles } from '@fluentui/react/lib/Stack';
import { DefaultPalette } from '@fluentui/react/lib/Styling';

After changing the imports to this:

import * as React from 'react';
import { Stack, IStackStyles, IStackTokens, IStackItemStyles } from '@fluentui/react';
import { DefaultPalette } from '@fluentui/react';

then the issue has gone.

Maybe we should update the demo code from documentation site?

kidlj avatar Aug 06 '21 17:08 kidlj

Because this issue has not had activity for over 150 days, we're automatically closing it for house-keeping purposes.

Still require assistance? Please, create a new issue with up-to date details.

msft-fluent-ui-bot avatar Jan 03 '22 20:01 msft-fluent-ui-bot