Skip to content
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

@wordpress/scripts: code compiled with npm start works, and with npm run build does not, when doing an import by relative path from a different package #23540

Closed
leoloso opened this issue Jun 28, 2020 · 2 comments
Labels
[Tool] WP Scripts /packages/scripts [Type] Help Request Help with setup, implementation, or "How do I?" questions.

Comments

@leoloso
Copy link

leoloso commented Jun 28, 2020

Describe the bug
I have a plugin with multiple blocks (under folder blocks/) which access shared components. These shared components are located under a different folder within the same plugin (under folder packages/):

- blocks/
+    block1/
+    block2/
- packages/
+   components/

Every block and package has its own package.json file.

The blocks import the shared components through a relative path:

import { SelectCard } from '../../../packages/components/src';

This code worked well with @wordpress/scripts version 8.1.0.

However, after upgrading to version 10.0.0, it works when running npm start but not with npm run build.

There are no compilation errors, but when executing the code in the browser (when creating a new post on Gutenberg), the screen is all white, and in the console I get this error:

TypeError: e[t] is undefined

When clicking there:

var n=r[t]={i:t,l:!1,exports:{}};return e[t].call(n.exports,n,n.exports,a),n.l=!0,n.exports}a.m=e,

To reproduce
Steps to reproduce the behavior:

  1. Reference a component not through the package name (eg: @wordpress/compose) but through the relative path within the project (eg: import { compose } from '../../packages/compose/src';
  2. Run npm run build
  3. Run Gutenberg (eg: a new post) in the browser

Expected behavior
I assume the relative path import across packages is not supported anymore, but this is not mentioned in the CHANGELOG, hence it's a guess.

If it is still supported, then code should work after running npm run build

If not supported anymore, then running npm start and npm run build should both fail (currently, npm start works well) and, ideally, the CHANGELOG should mention the steps needed to migrate the code

Editor version (please complete the following information):

  • @wordpress/scripts versions 10.0.0, 11.0.0 and 12.0.0
@leoloso
Copy link
Author

leoloso commented Jun 28, 2020

I have fixed the relative path import, and solved this issue. However, the different behavior between npm start and npm run build happens in other places too.

In another block, I display a GraphiQL client, with dependency:

"graphiql": "^0.17.5"

To import it:

import GraphiQL from 'graphiql';

It is used like this:

<GraphiQL
    fetcher={ graphQLFetcher }
    query={ query }
    variables={ variables }
    onEditQuery={ onEditQuery }
    onEditVariables={ onEditVariables }
    docExplorerOpen={ false }
/>

This code used to work well with @wordpress/scripts version 8.0.1. But after upgrading to version 10.0.0, npm start works, but npm run build throws several JS errors, including:

TypeError: Object(...) is not a function

Clicking on it, the code is this one:

Object(s.createElement)("path",{d:"M4.08 22.864l-1.1-.636L15.248.98l1.1.636z"})

@gziolo gziolo added [Type] Help Request Help with setup, implementation, or "How do I?" questions. [Tool] WP Scripts /packages/scripts labels Jun 29, 2020
@leoloso
Copy link
Author

leoloso commented Jul 1, 2020

Closed in favor of #23607, which is more specific and provides better information

@leoloso leoloso closed this as completed Jul 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Tool] WP Scripts /packages/scripts [Type] Help Request Help with setup, implementation, or "How do I?" questions.
Projects
None yet
Development

No branches or pull requests

2 participants